UserWarning: Do not pass a layer instance (such as LeakyReLU) as the activation argument of another layer. Instead, advanced activation layers should be used just like any other layer in a model. identifier=identifier.__class__.__name__))
时间: 2023-11-28 17:50:37 浏览: 86
1238: UserWarning: findfont: Font family [‘sans-serif’] not found. Falling back to DejaVu Sans.
这个 UserWarning 是因为在一个层的 activation 参数中传递了另一个层的实例,比如 LeakyReLU 等高级激活函数层。这样做是不被支持的,应该像使用任何其他层一样使用高级激活函数层。
例如,将 LeakyReLU 作为激活函数传递给 Dense 层时:
```python
from tensorflow.keras.layers import Dense, LeakyReLU
model = Sequential([
Dense(64, activation=LeakyReLU(alpha=0.1)),
...
])
```
应该将其改为:
```python
from tensorflow.keras.layers import Dense
from tensorflow.keras.layers import LeakyReLU
model = Sequential([
Dense(64),
LeakyReLU(alpha=0.1),
...
])
```
这样就可以避免这个 UserWarning 了。
阅读全文