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

后端 未结 8 1346
情歌与酒
情歌与酒 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:22

    This is a HIGHLY misleading error, as this is basically a general error, which might have NOTHING to do with floats.

    For example in my case it was caused by a string column of the pandas dataframe having some np.NaN values in it. Go figure!

    Fixed it by replacing them with empty strings:

    df.fillna(value='', inplace=True)
    

    Or to be more specific doing this ONLY for the string (eg 'object') columns:

    cols = df.select_dtypes(include=['object'])
    for col in cols.columns.values:
        df[col] = df[col].fillna('')
    
    0 讨论(0)
  • 2020-12-01 14:28

    You may want to check data types in input data set or array and than convert it to float32:

    train_X[:2, :].view()
    #array([[4.6, 3.1, 1.5, 0.2],
    #       [5.9, 3.0, 5.1, 1.8]], dtype=object)
    train_X = train_X.astype(np.float32)
    #array([[4.6, 3.1, 1.5, 0.2],
    #       [5.9, 3. , 5.1, 1.8]], dtype=float32)
    
    0 讨论(0)
提交回复
热议问题