我正在尝试为TF代理创建自己的PyEnvironment。 但是,此错误不断出现:
AttributeError:模块'tensorflow.python.ops.linalg.linear_operator_util'没有属性'matmul_with_broadcast'
我发现tensorflow-probability
似乎有问题,但是我安装了推荐的版本tensorflow-probability=0.7.0
https://github.com/tensorflow/agents/issues/91
我尝试重新安装和更新
tensorflow-gpu=2.0.0-beta1
tf-agents-nightly
tensorflow-probability=0.7.0
这是一个最小的代码示例:
from tf_agents.environments import py_environment
class myEnv(py_environment.PyEnvironment):
def __init__(self):
pass
def _reset(self):
pass
def _step(self, action):
pass
这是运行此最小示例时的完整错误消息:
Traceback (most recent call last): File ".\env_mwe.py", line 1, in <module>
from tf_agents.environments import py_environment File "C:\Python37\lib\site-packages\tf_agents\environments\__init__.py", line 18, in <module>
from tf_agents.environments import batched_py_environment File "C:\Python37\lib\site-packages\tf_agents\environments\batched_py_environment.py", line 33, in <module>
from tf_agents.environments import py_environment File "C:\Python37\lib\site-packages\tf_agents\environments\py_environment.py", line 29, in <module>
from tf_agents.trajectories import time_step as ts File "C:\Python37\lib\site-packages\tf_agents\trajectories\__init__.py", line 19, in <module>
from tf_agents.trajectories import time_step File "C:\Python37\lib\site-packages\tf_agents\trajectories\time_step.py", line 28, in <module>
from tf_agents.specs import array_spec File "C:\Python37\lib\site-packages\tf_agents\specs\__init__.py", line 20, in <module>
from tf_agents.specs.distribution_spec import DistributionSpec File "C:\Python37\lib\site-packages\tf_agents\specs\distribution_spec.py", line 22, in <module>
import tensorflow_probability as tfp File "E:\Users\tmp\AppData\Roaming\Python\Python37\site-packages\tensorflow_probability\__init__.py", line 78, in <module>
from tensorflow_probability.python import * # pylint: disable=wildcard-import File "E:\Users\tmp\AppData\Roaming\Python\Python37\site-packages\tensorflow_probability\python\__init__.py", line 22, in <module>
from tensorflow_probability.python import distributions File "E:\Users\tmp\AppData\Roaming\Python\Python37\site-packages\tensorflow_probability\python\distributions\__init__.py", line 64, in <module>
from tensorflow_probability.python.distributions.linear_gaussian_ssm import LinearGaussianStateSpaceModel File "E:\Users\tmp\AppData\Roaming\Python\Python37\site-packages\tensorflow_probability\python\distributions\linear_gaussian_ssm.py", line 41, in <module>
_matmul = linear_operator_util.matmul_with_broadcast AttributeError: module 'tensorflow.python.ops.linalg.linear_operator_util' has no attribute 'matmul_with_broadcast'
答案 0 :(得分:1)
要使用//...
// This rule should be familiar - it's standard part of espresso test
@Rule
public ActivityTestRule<(your activity)> mActivityRule = new ActivityTestRule<>((your activity class));
// ...
// Utility invocation in test
// start location updates - 25m/s (~55mph)
LatLng startPos = new LatLng(39.0, -77.0);
LocationUtils.startUpdates(mActivityRule.getActivity(),
new Handler(Looper.getMainLooper()),
startPos, 340, 25);
// ...
// (In a test utility class in this example: LocationUtils.java)
// Utility - uses SphericalUtil to maintain a position based on
// initial starting position, heading and movement value (in
// meters) applied every 1 second. (So a movement value
// of 25 equates to 25m/s which equates to ~55MPH)
public static void startUpdates(
final Activity activity, final Handler mHandler, final LatLng pos,
final double heading, final double movement) {
mHandler.postDelayed(new Runnable() {
private LatLng myPos = new LatLng(pos.latitude,pos.longitude);
@Override
public void run() {
Location mockLocation = new Location(LocationManager.GPS_PROVIDER); // a string
mockLocation.setLatitude(myPos.latitude); // double
mockLocation.setLongitude(myPos.longitude);
mockLocation.setAltitude(100);
mockLocation.setTime(System.currentTimeMillis());
mockLocation.setAccuracy(1);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
mockLocation.setElapsedRealtimeNanos(SystemClock.elapsedRealtimeNanos());
}
LocationServices.getFusedLocationProviderClient(activity).setMockMode(true);
LocationServices.getFusedLocationProviderClient(activity).setMockLocation(mockLocation);
// compute next position
myPos = SphericalUtil.computeOffset(myPos, movement, heading);
mHandler.postDelayed(this, 1000);
}
}, 1000);
}
,需要2.0.0beta1
。
答案 1 :(得分:0)
找到了!
要在$('#audio').attr("src","path_to_audio.wav");
$('#audio').play();
中使用tensorflow-gpu
,需要安装tensorflow-probability
因此tfp-nightly
做到了