When training a small model today, this error occurred:
TypeError: Fetch argument 2.19779 has invalid type <class 'numpy.float32'>,
must be a string or Tensor. (Can not convert a float32 into a Tensor or Operation.)
In the output, you can see that there is a line of correct output, that is, the Loss calculation is performed once, and then this error is thrown during the second calculation. In the error message, 2.19779 happens to be the result of the first Loss calculation.
Found the same problem in stackoverflow (see TypeError: Fetch argument has invalid type float32, must be a string or Tensor
).
In fact, the reason for the error is very simple. My previous execution statement was like this:
_, loss = sess.run([optimizer, loss], feed_dict={X:input_batch, Y:target_batch})
The problem is that loss is redefined ! ! , Which is in this form:
loss = sess.run(loss)
In this way, the first run is no problem. If the result of the first calculation of loss is 10, then the loss is redefined, that is, the previous loss is the node for calculating the loss value. After the first run, it becomes A common variable is also assigned a value of 10, so the second operation becomes:
loss = sess.run(10)
The above type error occurred.
Therefore, the question of naming must not be sloppy, remember to remember.
Read More:
- How to Solve Swagger error: typeerror: failed to fetch
- [Solved] Mybatis insert Error: Cause: java.sql.SQLException: SQL String cannot be empty
- [Solved] No validator could be found for constraint ‘javax.validation.constraints.NotBlank’ validating type ‘java.lang.String’
- Java learning unreported exception java.io.IOException ; must be caught or declared to be thrown
- Mybatis Error: Error instantiating class bakou.entity.Person with invalid types () or value)
- [Solved] HttpMessageNotReadableException: JSON parse error: Unrecognized field “xxxx“
- [Solved] Error attempting to get column ‘xxxx_time‘ from result set. Cause: java.sql.SQLFeatureNotSupportedEx
- [Solved] Java Run Error: For input string: “XXX”
- Eclipse Error: There are no resources that can be added or removed from the server.
- How to Solve JAR pack error: Error resolving template [/userInfo], template might not exist or might not be accessib
- [Solved] Android Could not determine artifacts for XXXX: Skipped due to earlier error
- [Solved] Log Error: NAN OR INFINITY
- [Solved] Error resolving template [x] template might not exist or might not be accessible by any of the con
- C++ String case conversion and transform, tower, upper, usage
- Tensorflow Error raise RuntimeError(‘The Session graph is empty. Add operations to the ‘ RuntimeError:
- [Solved] Error resolving template template might not exist or might not be accessible
- How to convert a Java string into a number (stringtonumber)
- JAVA: How to Delete the Last Bit of String
- Idea error: (44,22) Java: constant string too long
- Problems and causes of Java’s main function format (public static void main (string args()))