【发布时间】:2021-01-12 00:44:08
【问题描述】:
我正在使用this 教程为我的模型学习迁移学习。我们可以看到他的单个 epoch 平均为 1 秒。
Epoch 1/100
1080/1080 [==============================] - 10s 10ms/step - loss: 3.6862 - acc: 0.2000
Epoch 2/100
1080/1080 [==============================] - 1s 1ms/step - loss: 3.0746 - acc: 0.2574
Epoch 3/100
1080/1080 [==============================] - 1s 1ms/step - loss: 2.6839 - acc: 0.3185
Epoch 4/100
1080/1080 [==============================] - 1s 1ms/step - loss: 2.3929 - acc: 0.3583
Epoch 5/100
1080/1080 [==============================] - 1s 1ms/step - loss: 2.1382 - acc: 0.3870
Epoch 6/100
1080/1080 [==============================] - 1s 1ms/step - loss: 1.7810 - acc: 0.4593
但是当我为我的 cifar 模型遵循几乎相同的代码时,我的单个 epoch 需要大约 1 小时才能运行。
Train on 50000 samples
3744/50000 [=>............................] - ETA: 43:38 - loss: 3.3223 - acc: 0.1760
1
我的代码是
from tensorflow.keras.applications import ResNet50
from tensorflow.keras.layers import GlobalAveragePooling2D, Dense, Dropout
from tensorflow.keras import Model
(x_train, y_train), (x_test, y_test) = tf.keras.datasets.cifar10.load_data()
x_train = x_train / 255.0
x_test = x_test / 255.0
y_train = to_categorical(y_train)
y_test = to_categorical(y_test)
base_model = ResNet50(weights= None, include_top=False, input_shape= (32,32,3))
x = base_model.output
x = GlobalAveragePooling2D()(x)
x = Dropout(0.4)(x)
predictions = Dense(10 , activation= 'softmax')(x)
model = Model(inputs = base_model.input, outputs = predictions)
model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['acc'])
hist = model.fit(x_train, y_train)
请注意,我为此模型使用了 cifar 10 数据集。我的代码或数据有什么问题吗?我该如何改进呢? 1 epoch 需要 1 小时太长了。我也有 NVIDIA MX-110 2GB,TensorFlow 正在使用它。
【问题讨论】:
标签: python tensorflow machine-learning keras deep-learning