attributeError:' dtype'对象没有属性' type'
当我收到培训会产生损失和准确性(它们都是张量)时,我想使用tf.compat.v1.keras.utils.progbar()功能和更新方法来更新它们,以便我可以得到更好查看训练过程,但是发生以下错误:
File "E:/python/maml_mnist/train.py", line 64, in <module>
,('accuracy',mean_train_meta_acc)]
File "C:\Users\12130\AppData\Roaming\Python\Python36\site-
packages\tensorflow\python\keras\utils\generic_utils.py", line 442, in update
avg = np.mean(self._values[k][0] / max(1, self._values[k][1]))
File "<__array_function__ internals>", line 6, in mean
File "E:\python\lib\site-packages\numpy\core\fromnumeric.py", line 3373, in mean
out=out, **kwargs)
File "E:\python\lib\site-packages\numpy\core\_methods.py", line 170, in _mean
ret = ret.dtype.type(ret / rcount)
AttributeError: 'DType' object has no attribute 'type' here
代码如下:
train_progbar = tf.compat.v1.keras.utils.Progbar(train_data.steps)
for i in range(train_data.steps):
batch_train_loss,batch_train_acc = maml.train_on_batch(train_data.get_one_batch(),
inner_optimizer,
inner_step=1,
outer_optimizer=outer_optimizer)
train_meta_loss.append(batch_train_loss)
train_meta_acc.append(batch_train_acc)
mean_train_meta_loss = np.mean(train_meta_loss)
mean_train_meta_acc = np.mean(batch_train_acc)
train_progbar.update(i+1
,[('loss',mean_train_meta_loss)
,('accuracy',mean_train_meta_acc)]
)
我知道错误是由于解决平均值而引起的,但我不知道如何修复它以成功运行代码。
我的TensorFlow版本是1.14.0。
When I receive the training produces loss and accuracy (they are both tensor), I would like to use tf.comPat.v1.Keras.Utils.Progbar()function and the update method to update them, so that I can get a better look training process, but the following error occured:
File "E:/python/maml_mnist/train.py", line 64, in <module>
,('accuracy',mean_train_meta_acc)]
File "C:\Users\12130\AppData\Roaming\Python\Python36\site-
packages\tensorflow\python\keras\utils\generic_utils.py", line 442, in update
avg = np.mean(self._values[k][0] / max(1, self._values[k][1]))
File "<__array_function__ internals>", line 6, in mean
File "E:\python\lib\site-packages\numpy\core\fromnumeric.py", line 3373, in mean
out=out, **kwargs)
File "E:\python\lib\site-packages\numpy\core\_methods.py", line 170, in _mean
ret = ret.dtype.type(ret / rcount)
AttributeError: 'DType' object has no attribute 'type' here
The code is as follows:
train_progbar = tf.compat.v1.keras.utils.Progbar(train_data.steps)
for i in range(train_data.steps):
batch_train_loss,batch_train_acc = maml.train_on_batch(train_data.get_one_batch(),
inner_optimizer,
inner_step=1,
outer_optimizer=outer_optimizer)
train_meta_loss.append(batch_train_loss)
train_meta_acc.append(batch_train_acc)
mean_train_meta_loss = np.mean(train_meta_loss)
mean_train_meta_acc = np.mean(batch_train_acc)
train_progbar.update(i+1
,[('loss',mean_train_meta_loss)
,('accuracy',mean_train_meta_acc)]
)
I know that the error was caused by solving the average, but I don't know how to fix it to make the code run successfully.
My version of TensorFlow is 1.14.0.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论