簡體   English   中英

Tensorflow model.fit 卡在第一個 epoch

[英]Tensorflow model.fit stuck at first epoch

我目前正在嘗試在 FashionMNIST 數據集上構建 Tensorflow CNN 模型。

環境:Tensorflow 版本:2.3.0 CUDA Toolkit 10.1 cuDNN v7.6 python 3.8.3

腳本:

import tensorflow as tf 
print("Tensorflow Version:", tf.__version__)

from __future__ import absolute_import, division, print_function, unicode_literals
from tensorflow.keras import datasets, layers, models
import matplotlib.pyplot as plt
import numpy as np
# TensorFlow and tf.keras
import tensorflow as tf
from tensorflow import keras
#### Import the Fashion MNIST dataset
fashion_mnist = keras.datasets.fashion_mnist
(train_images, train_labels), (test_images, test_labels) = fashion_mnist.load_data()
class_names = ['T-shirt/top', 'Trouser', 'Pullover', 'Dress', 'Coat',
               'Sandal', 'Shirt', 'Sneaker', 'Bag', 'Ankle boot']

train_images1 = train_images[:,:,:,np.newaxis]
test_images1 = test_images[:,:,:,np.newaxis]
##Scale these values to a range of 0 to 1 before feeding them to the neural network model
### Normalize pixel values to be between 0 and 1
train_images = train_images / 255.0
test_images = test_images / 255.0

##Create the convolutional base
model = models.Sequential()
model.add(layers.Conv2D(32, (3, 3), activation='relu', input_shape=(28,28,1)))
model.add(layers.MaxPooling2D((2, 2)))
model.add(layers.Conv2D(64, (3, 3), activation='relu'))
model.add(layers.MaxPooling2D((2, 2)))
model.add(layers.Conv2D(64, (3, 3), activation='relu'))
model.summary()
model.add(layers.Flatten())
model.add(layers.Dense(64, activation='relu'))
model.add(layers.Dense(10))
model.summary()
model.compile(optimizer='adam',
              loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True),
              metrics=['accuracy'])

###Train the model
##Feed the model
history = model.fit(train_images1, train_labels, epochs=10, 
                    validation_data=(test_images1, test_labels))

model.fit ,它顯示了一個Epoch 1/10很長一段時間沒有任何進度條而沒有顯示任何錯誤。 除此之外,我還發現定義模型花費的時間比預期的要長; 約2分鍾。

當您使用 model.fit() 時,程序會加載數據,這需要很多時間。

嘗試在 colab 上運行相同的代碼。 你的代碼很好。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM