Python 我的tensorflow模型在第一个纪元之前就卡住了
操作系统:windows 10 TensorFlow:2.0.0 Keras:2.2.4Python 我的tensorflow模型在第一个纪元之前就卡住了,python,tensorflow,keras,deep-learning,mnist,Python,Tensorflow,Keras,Deep Learning,Mnist,操作系统:windows 10 TensorFlow:2.0.0 Keras:2.2.4 try: # %tensorflow_version only exists in Colab. %tensorflow_version 2.x except Exception: pass import tensorflow as tf print("Tensorflow Version:", tf.__version__) from __future__ import
try:
# %tensorflow_version only exists in Colab.
%tensorflow_version 2.x
except Exception:
pass
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))
###Evaluate the model
plt.plot(history.history['accuracy'], label='train_accuracy')
plt.plot(history.history['val_accuracy'], label = 'val_accuracy')
plt.xlabel('Epoch')
plt.ylabel('Accuracy')
plt.ylim([0.5, 1])
plt.legend(loc='lower right')
test_loss, test_acc = model.evaluate(test_images1, test_labels, verbose=2)
我正在为MNIST数据集培训CNN。我使用python mnist模块加载数据集。
当我尝试运行代码时,它会在时代开始之前卡住。
我的代码:
我的输出:
2020-03-10 08:10:18.061068: I tensorflow/core/platform/cpu_feature_guard.cc:145] This TensorFlow binary is optimized with Intel(R) MKL-DNN to use the following CPU instructions in performance critical operations: AVX AVX2
To enable them in non-MKL-DNN operations, rebuild TensorFlow with the appropriate compiler flags.
2020-03-10 08:10:18.069858: I tensorflow/core/common_runtime/process_util.cc:115] Creating new thread pool with default inter op setting: 4. Tune using inter_op_parallelism_threads for best performance.
我忘了什么吗?请参考工作代码为MNIST数据集培训CNN
(操作系统:windows 10、TensorFlow:2.0.0和Keras:2.2.4)
@穆罕默德·法哈迪——如果我已经回答了你的问题,请你接受并投票表决。非常感谢。
try:
# %tensorflow_version only exists in Colab.
%tensorflow_version 2.x
except Exception:
pass
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))
###Evaluate the model
plt.plot(history.history['accuracy'], label='train_accuracy')
plt.plot(history.history['val_accuracy'], label = 'val_accuracy')
plt.xlabel('Epoch')
plt.ylabel('Accuracy')
plt.ylim([0.5, 1])
plt.legend(loc='lower right')
test_loss, test_acc = model.evaluate(test_images1, test_labels, verbose=2)