. Advertisement .
..3..
. Advertisement .
..4..
The error: “NotImplementedError: Cannot convert a symbolic Tensor (2nd_target:0) to a NumPy array” is a common error that can show up in many ways. In this blog, we will go through some of the ways you can fix this issue. Read on.
How To Solve The Error: “NotImplementedError: Cannot convert a symbolic Tensor (2nd_target:0) to a NumPy array”?
You’re attempting to resolve a NumPy array problem. You used 2 loss functions, then you creat the model:
l2 = K.eval(l_2nd(self.beta))
l1 = K.eval(l_1st(self.alpha))
self.model.compile(opt, [l2, l1])
while upgrading from numpy 1.19
to 1.20
& doing ray
‘s RLlib, this problem happen also. On the other hand, when mixing symbolic tensor with a non-symbolic type, like a numpy. For example, its not recommended to have something.
When you train, you get the warning message as follow:
NotImplementedError: Cannot convert a symbolic Tensor (2nd_target:0) to a numpy array.
How To Solve The Error: “NotImplementedError: Cannot convert a symbolic Tensor (2nd_target:0) to a NumPy array”?
Below are the best suggestions for your reference, select the best option!
Approach 1: Downgrade NumPy
Simply downgrade NumPy to version 1.19.5 and your problem will be resolved. To downgrade the NumPy version, simply run the following command:
pip install numpy==1.19.5
Approach 2: Install tensorflow again
Simply reinstall tensorflow. In the terminal of your present conda environment, type these commands.
pip uninstall tensorflow
pip install tensorflow
Approach 3: Convert all to symbolic tensors
You can convert all to the symbolic tensors like:
def my_mse_loss_b(b):
def mseb(y_true, y_pred):
...
a = K.ones_like(y_true) #use Keras instead so they are all symbolic
return K.mean(K.square(y_pred - y_true)) + a
return mseb
Conclusion
We hope you enjoyed our article about the error. With this knowledge, we know that you can fix your error: “NotImplementedError: Cannot convert a symbolic Tensor (2nd_target:0) to a NumPy array” quickly by following these steps! If you still have any other questions about fixing this syntax error, please leave a comment below. Thank you for reading!
Leave a comment