问题描述
限时送ChatGPT账号..我是机器学习的新手.我正在尝试在 Tensorflow 2.0 中制作一个简单的 RNN,但我遇到了障碍.我已将其简化为重现问题的最小示例.这个最小示例的目标是让 RNN 学习重复输出 1.0.
I'm new to machine learning. I'm trying to make a simple RNN in Tensorflow 2.0 but I'm hitting a snag. I've reduced it to a minimal example that reproduces the problem. The goal of this minimal example is for the RNN to learn to output 1.0 repeatedly.
import os
import sys
import math
from random import shuffle
import numpy as np
import tensorflow as tf
from time import time as time
epochs = 200
batch_size = 32
chunk_length = 64
features = 10
def main():
train_dataset = np.zeros([batch_size, chunk_length, features]) + 1
test_dataset = np.zeros([batch_size, chunk_length, features]) + 1
with tf.device('/gpu:0'):
model = tf.keras.Sequential([
tf.keras.layers.Bidirectional(tf.keras.layers.LSTM(
64, return_sequences=True)),
tf.keras.layers.Bidirectional(tf.keras.layers.LSTM(32)),
tf.keras.layers.Dense(64, activation='relu'),
tf.keras.layers.Dense(1, activation='sigmoid')
])
modelpile(loss='mean_absolute_error',
optimizer='adam',
metrics=['accuracy'])
history = model.fit(train_dataset, batch_size=batch_size, epochs=epochs)
test_loss, test_acc = model.evaluate(test_dataset)
print('Test Loss: {}'.format(test_loss))
print('Test Accuracy: {}'.format(test_acc))
if __name__ == '__main__':
main()
当我运行它时,我得到 ValueError: Arguments and signature arguments do not match: 56 57
.如果我注释掉最后一层,我会得到 ValueError: Arguments and signature arguments do not match: 50 51
.如果我注释掉最后两层,我会得到 ValueError: Arguments and signature arguments do not match: 44 45
.
When I run this I get ValueError: Arguments and signature arguments do not match: 56 57
. If I comment out the last layer, I get ValueError: Arguments and signature arguments do not match: 50 51
. If I comment out the last two layers I get ValueError: Arguments and signature arguments do not match: 44 45
.
我尝试修改我提供的所有常量(epochs、batch_size、chunk_length 和 features),但这些对错误没有影响.我还尝试将 1 逐元素添加到 numpy 数组中,但这也没有效果.
I have tried modifying all of the constants I provide (epochs, batch_size, chunk_length, and features) but these have no effect on the error. I also tried removing the element-wise addition of 1 to the numpy arrays, but this also has no effect.
这是 TensorFlow 中的错误还是我在做一些愚蠢的事情?
Is this a bug in TensorFlow or am I doing something stupid?
推荐答案
我使用的是 tensorflow 版本 1.13.1 并且没有 GPU,但希望这仍然可以解决问题.似乎您只提供网络输入数据 (x),但没有响应数据 (y).所以模型没有什么可以学习的.我只添加了响应数据 train_Y_dataset 和 test_Y_dataset.以下代码在 tensorflow 1.13.1 中对我有用,请参阅更改注释:
I'm on tensorflow version 1.13.1 and no GPU, but hopefully this still fixes the problems. It seems like you are only feeding your network input data (x), but no respond data (y). So there is nothing for the model to learn. I only added the response data train_Y_dataset and test_Y_dataset. The following code worked for me in tensorflow 1.13.1, see comment for changes:
import os
import sys
import math
from random import shuffle
import numpy as np
import tensorflow as tf
from time import time as time
这篇关于Tensorflow 2.0 Beta:Model.fit() 抛出 ValueError:参数和签名参数不匹配:56 57的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论