how to convert numpy array to keras tensor

后端 未结 1 952
粉色の甜心
粉色の甜心 2020-12-17 17:04

When using the keras model to do predict, I got the error below
AttributeError: \'Tensor\' object has no attribute \'ndim\'
The reason is that the weights is numpy a

相关标签:
1条回答
  • 2020-12-17 17:53

    In Tensorflow it can be done the following way:

    import tensorflow.keras.backend as K
    import numpy as np
    
    a = np.array([1,2,3])
    b = K.constant(a)
    print(b)
    
    # <tf.Tensor 'Const_1:0' shape=(3,) dtype=float32>
    
    print(K.eval(b))
    
    # array([1., 2., 3.], dtype=float32)
    

    In raw keras it should be done replacing import tensorflow.keras.backend as K with from keras import backend as K.

    0 讨论(0)
提交回复
热议问题