我的代碼不起作用。我一直在關注的教程是:https ://www.youtube.com/watch?v=t0EzVCvQjGE&t=1052s 。沒有錯誤或任何東西,但它沒有顯示最后的損失、準確性和訓練程序(我使用的是 vscode),就像在視頻中那樣(視頻中的 17:53)。這是我的代碼:
import cv2 as cv2
import numpy as numpy
import matplotlib.pyplot as plt
from tensorflow.keras import datasets, layers, models
(training_images, training_labels), (testing_images, testing_labels) = datasets.cifar10.load_data()
training_images, testing_images = training_images / 255, testing_images / 255
class_names = ['Plane', 'Car', 'Bird', 'Cat', 'Deer', 'Dog', 'Frog', 'Horse', 'Ship', 'Truck']
for i in range(16):
plt.subplot(4,4,i 1)
plt.xticks([])
plt.yticks([])
plt.imshow(training_images[i], cmap=plt.cm.binary)
plt.xlabel(class_names[training_labels[i][0]])
plt.show()
training_images = training_images[:5000]
training_labels = training_labels[:5000]
testing_images = testing_images[:1000]
testing_labels = testing_labels[:1000]
model = models.Sequential()
model.add(layers.Conv2D(32, (3,3), activation='relu', input_shape=(32,32,3)))
model.add(layer.MaxPooling2D((2,2)))
model.add(layers.Conv2D(32, (3,3), activation='relu'))
model.add(layer.MaxPooling2D((2,2)))
model.add(layers.Conv2D(32, (3,3), activation='relu'))
model.add(layers.flatten())
model.add(layers.Dense(64, activation='relu'))
model.add(layers.Dense(10, activation='softmax'))
model.complie(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy'])
model.fit(training_images, training_labels, epochs=10, validation_data=(testing_images, testing_labels))
loss, accuracy = model.evaluate(testing_images, testing_labels)
print(f"Loss: {loss}")
print(f"Accuracy: {accuracy}")
model.save('image_classifier.model')
此外,我的終端中還顯示了一些內容:
I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX2
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
OMP: Error #15: Initializing libiomp5, but found libiomp5md.dll already initialized.
OMP: Hint This means that multiple copies of the OpenMP runtime have been linked into the program. That is dangerous, since it can degrade performance or cause incorrect results. The best thing to do is to ensure that only a single OpenMP runtime is linked into the process, e.g. by avoiding static linking of the OpenMP runtime in any library. As an unsafe, unsupported, undocumented workaround you can set the environment variable KMP_DUPLICATE_LIB_OK=TRUE to allow the program to continue to execute, but that may cause crashes or silently produce incorrect results. For more information, please see http://openmp.llvm.org/
有誰知道發生了什么?如果有,請回復。謝謝!
uj5u.com熱心網友回復:
從我在這里查看的內容來看,添加這兩行應該可以在您的代碼中使用。我認為您的 keras 安裝有問題。
import os
os.environ['KMP_DUPLICATE_LIB_OK']='True'
為了始終避免添加這些行,我想您應該將其添加到系統中的環境變數中。
另一種解決方案是洗掉libiomp5md.dll庫中的檔案。您可以檢查該檔案是否存在于您的目錄中。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/491606.html
