首页 > 解决方案 > Keras 顺序模型在本地机器上工作,但 AWS 抛出关于层的错误

问题描述

我在 Keras 中设置了一个顺序模型

agent = keras.Sequential(
    [
        layers.Dense(100, activation="relu", name="layer1"),
        layers.Dense(100, activation="relu", name="layer2"),
        layers.Dense(22, name="output"),
    ]
)

尝试在 AWS 上运行它会给我以下错误:

Using TensorFlow backend.
Traceback (most recent call last):
  File "single_player_keras_repeat_playthrough.py", line 30, in <module>
    layers.Dense(22, name="output"),
  File "/home/ubuntu/anaconda3/envs/tensorflow2_p36/lib/python3.6/site-packages/tensorflow_core/python/training/tracking/base.py", line 457, in _method_wrapper
    result = method(self, *args, **kwargs)
  File "/home/ubuntu/anaconda3/envs/tensorflow2_p36/lib/python3.6/site-packages/tensorflow_core/python/keras/engine/sequential.py", line 116, in __init__
    self.add(layer)
  File "/home/ubuntu/anaconda3/envs/tensorflow2_p36/lib/python3.6/site-packages/tensorflow_core/python/training/tracking/base.py", line 457, in _method_wrapper
    result = method(self, *args, **kwargs)
  File "/home/ubuntu/anaconda3/envs/tensorflow2_p36/lib/python3.6/site-packages/tensorflow_core/python/keras/engine/sequential.py", line 161, in add
    'Found: ' + str(layer))
TypeError: The added layer must be an instance of class Layer. Found: <keras.layers.core.Dense object at 0x7fb3fac02518>

这段代码在我的本地机器上运行良好。我究竟做错了什么?

标签: pythontensorflowkerasamazon-ec2

解决方案


推荐阅读