layers.experimental.preprocessing.Rescaling(1./255, input_shape=(24, 24, 1)), layers.Conv2D(24, 3, padding='same', activation='relu'), layers.MaxPooling2D(), layers.Conv2D(32, 3, padding='same', activation='relu'), layers.MaxPooling2D(), layers.Conv2D(64, 3, padding='same', activation='relu'), layers.MaxPooling2D(), layers.Dropout(0.2), layers.Flatten(), layers.Dense(96, activation='relu'), layers.Dense(15)]改写第一行代码绕开experimental模块
时间: 2023-11-20 22:06:49 浏览: 156
可以使用以下代码绕开`experimental`模块:
```
from tensorflow.keras.layers import Input, Conv2D, MaxPooling2D, Dropout, Flatten, Dense
from tensorflow.keras.models import Model
inputs = Input(shape=(24, 24, 1))
x = Conv2D(24, 3, padding='same', activation='relu')(inputs)
x = MaxPooling2D()(x)
x = Conv2D(32, 3, padding='same', activation='relu')(x)
x = MaxPooling2D()(x)
x = Conv2D(64, 3, padding='same', activation='relu')(x)
x = MaxPooling2D()(x)
x = Dropout(0.2)(x)
x = Flatten()(x)
x = Dense(96, activation='relu')(x)
outputs = Dense(15)(x)
model = Model(inputs=inputs, outputs=outputs)
```
这里使用了`Input`和`Model`代替了`layers.Input`和`models.Model`,并将所有的层都直接引入了,而不是使用`experimental.preprocessing.Rescaling`和`layers.experimental`。
阅读全文