Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/316.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python TF v2属性错误:';张量';对象没有属性';numpy';内损失函数_Python_Numpy_Tensorflow_Eager Execution - Fatal编程技术网

Python TF v2属性错误:';张量';对象没有属性';numpy';内损失函数

Python TF v2属性错误:';张量';对象没有属性';numpy';内损失函数,python,numpy,tensorflow,eager-execution,Python,Numpy,Tensorflow,Eager Execution,我得到的错误是AttributeError:“Tensor”对象在尝试将tf Tensor更改为numpy数组,然后再更改回Tensor时没有属性“numpy”。给出错误的代码如下 network = models.Sequential() network.add(layers.Dense(512,activation='relu')) network.add(layers.Dense(10,activation='linear')) def root_mean_squared_error(y

我得到的错误是AttributeError:“Tensor”对象在尝试将tf Tensor更改为numpy数组,然后再更改回Tensor时没有属性“numpy”。给出错误的代码如下

network = models.Sequential()
network.add(layers.Dense(512,activation='relu'))
network.add(layers.Dense(10,activation='linear'))

def root_mean_squared_error(y_true, y_pred):
        y_pred = y_pred.numpy()
        y_pred = tf.convert_to_tensor(y_pred)
        return K.sqrt(K.mean(K.square(y_pred - y_true)))

network.compile(optimizer='rmsprop',
                loss=root_mean_squared_error,
                metrics=['accuracy'])

network.fit(train_images,cat_train_labels,epochs=5,batch_size=28)
在这里,我只是想让这个基本实现正常工作,因为我在使用.numpy()时遇到了一些问题

似乎没有启用“渴望执行”,但根据我的尝试,我无法启用它


非常感谢您的帮助。

欢迎使用SO!您能否制作一个最小的可复制示例,请参见: