Tensorflow 2.0 Beta:Model.fit() 抛出 ValueError:参数和签名参数不匹配:56 57

编程入门 行业动态 更新时间:2024-10-28 04:20:10
本文介绍了Tensorflow 2.0 Beta:Model.fit() 抛出 ValueError:参数和签名参数不匹配:56 57的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送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:关键词]

本文发布于:2023-05-01 00:43:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1401819.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:参数   抛出   不匹配   Beta   Model

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!