My code isn't working. The tutorial that I've been following is: https://www.youtube.com/watch?v=t0EzVCvQjGE&t=1052s. There's no errors or anything, but it doesn't show the loss, accuracy, and training process at the end (I'm using vscode), like it does in the video (17:53 in the video). Here's my code:
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')
Furthermore, there's also something that shows in my terminal:
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/
Does anyone know what's going on? If so, please reply. Thanks!
CodePudding user response:
From what I have looked up over here adding these two lines should work in your code. I assume something is wrong with your installation of keras.
import os
os.environ['KMP_DUPLICATE_LIB_OK']='True'
To always avoid adding these lines I suppose you should add that to env variables in the system.
Another solution is to delete libiomp5md.dll
file in your libraries. You could check to see if that file exists in your directories.