Tensorflow - ValueError: Failed to convert a NumPy array to a Tensor (Unsupported object type float)

后端 未结 8 1368
情歌与酒
情歌与酒 2020-12-01 13:45

Continuation from previous question: Tensorflow - TypeError: 'int' object is not iterable

My training data is a list of lists each comprised of 1000 floats. F

8条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-01 14:20

    I had many different inputs and target variables and didn't know which one was causing the problem.

    To find out on which variable it breaks you can add a print value in the library package using the path is specified in your stack strace:

          File "C:\Users\bencu\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_core\python\framework\constant_op.py", line 96, in convert_to_eager_tensor
            return ops.EagerTensor(value, ctx.device_name, 
    

    Adding a print statement in this part of the code allowed me to see which input was causing the problem:

    constant_op.py:

      ....
          dtype = dtype.as_datatype_enum
        except AttributeError:
          dtype = dtypes.as_dtype(dtype).as_datatype_enum
      ctx.ensure_initialized()
      print(value) # <--------------------- PUT PRINT HERE
      return ops.EagerTensor(value, ctx.device_name, dtype)
    

    After observing which value was problematic conversion from int to astype(np.float32) resolved the problem.

提交回复
热议问题