someintuition 2020-11-26 23:22 采纳率: 50%
浏览 143
已结题

新手学tensorflow2.0,自己制作的数据集,是不是不对?

我在尝试制作了一个数据集,训练集形状是(130, 59, 7, 7, 3),目标集(130,)
以下是代码部分


```

log_dir = '.\logs'
tensorboard_callback = tf.keras.callbacks.TensorBoard(log_dir=log_dir, histogram_freq=1)
inputs = keras.layers.Input(shape=(59,7,7,3))
x = keras.layers.Dense(64 activation='relu')(inputs)
x = keras.layers.Dense(64, activation='relu')(x)
predictions = keras.layers.Dense(1)(x)
model = keras.models.Model(inputs=inputs, outputs=predictions)
model.compile(optimizer='adam', loss='mae')
print("================开始训练======================")
model.fit(train_data, train_label,epochs=10,
              verbose=1,callbacks=[tensorboard_callback])  # 开始训练
```
以下是报错:

```

 32/130 [======>.......................] - ETA: 2sTraceback (most recent call last):
  File "D:/tensorflow/tensor_sale.py", line 48, in <module>
    verbose=1,callbacks=[tensorboard_callback])  # 开始训练
  File "D:\miniconda\envs\tensorflow\lib\site-packages\tensorflow_core\python\keras\engine\training.py", line 728, in fit
    use_multiprocessing=use_multiprocessing)
  File "D:\miniconda\envs\tensorflow\lib\site-packages\tensorflow_core\python\keras\engine\training_v2.py", line 324, in fit
    total_epochs=epochs)
  File "D:\miniconda\envs\tensorflow\lib\site-packages\tensorflow_core\python\keras\engine\training_v2.py", line 123, in run_one_epoch
    batch_outs = execution_function(iterator)
  File "D:\miniconda\envs\tensorflow\lib\site-packages\tensorflow_core\python\keras\engine\training_v2_utils.py", line 86, in execution_function
    distributed_function(input_fn))
  File "D:\miniconda\envs\tensorflow\lib\site-packages\tensorflow_core\python\eager\def_function.py", line 457, in __call__
    result = self._call(*args, **kwds)
  File "D:\miniconda\envs\tensorflow\lib\site-packages\tensorflow_core\python\eager\def_function.py", line 520, in _call
    return self._stateless_fn(*args, **kwds)
  File "D:\miniconda\envs\tensorflow\lib\site-packages\tensorflow_core\python\eager\function.py", line 1823, in __call__
    return graph_function._filtered_call(args, kwargs)  # pylint: disable=protected-access
  File "D:\miniconda\envs\tensorflow\lib\site-packages\tensorflow_core\python\eager\function.py", line 1141, in _filtered_call
    self.captured_inputs)
  File "D:\miniconda\envs\tensorflow\lib\site-packages\tensorflow_core\python\eager\function.py", line 1224, in _call_flat
    ctx, args, cancellation_manager=cancellation_manager)
  File "D:\miniconda\envs\tensorflow\lib\site-packages\tensorflow_core\python\eager\function.py", line 511, in call
    ctx=ctx)
  File "D:\miniconda\envs\tensorflow\lib\site-packages\tensorflow_core\python\eager\execute.py", line 67, in quick_execute
    six.raise_from(core._status_to_exception(e.code, message), None)
  File "<string>", line 3, in raise_from
tensorflow.python.framework.errors_impl.InvalidArgumentError:  Incompatible shapes: [32,59,7,7,1] vs. [32,1]
     [[node loss/dense_2_loss/sub (defined at \miniconda\envs\tensorflow\lib\site-packages\tensorflow_core\python\framework\ops.py:1751) ]] [Op:__inference_distributed_function_991]

```
求帮忙看看咋回事,我是菜鸟一枚。

  • 写回答

1条回答 默认 最新

  • BryceRui 2020-11-27 11:31
    关注

    x = keras.layers.Dense(64 activation='relu')(inputs)之前应该先拉平成1维的 

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 6月6日
  • 已采纳回答 5月29日

悬赏问题

  • ¥15 C++ 菜单窗口独立出来,可以随意移动放大缩小。
  • ¥15 java代码写在记事本上后在cmd上运行时无报错但又没生成文件
  • ¥15 关于#python#的问题:在跑ldsc数据整理的时候一直抱这种错误,要么--out识别不了参数,要么--merge-alleles识别不了参数(操作系统-linux)
  • ¥15 PPOCRLabel
  • ¥15 网友们我该怎么办啊,急
  • ¥15 混合键合键合机对准标识
  • ¥100 现在不懂的是如何将当前的相机中的照片,作为纹理贴图,映射到扫描出的模型上
  • ¥15 目标跟踪,计算机视觉
  • ¥15 魔霸ROG7 pro,win11.息屏后会显示黑屏,如图,如何解决?(关键词-重新启动)
  • ¥15 有没有人知道这是哪里出了问题啊?要怎么改呀?