Reputation: 11
It is a traffic sign recognition project where I have already run the training code and got the training accuracy. Then when I run testing code it gives me an error. The laptop's camera gets turned on but I don't get any interface to test my inputs.
The code is:
import img as img
import numpy as np
import cv2
import os
import pickle
from keras.models import load_model
import tensorflow as tf
#############################################
frameWidth = 640 # CAMERA RESOLUTION
frameHeight = 480
brightness = 180
threshold = 0.75 # PROBABLITY THRESHOLD
font = cv2.FONT_HERSHEY_SIMPLEX
##############################################
# SETUP THE VIDEO CAMERA
cap = cv2.VideoCapture(0)
cap.set(3, frameWidth)
cap.set(4, frameHeight)
cap.set(10, brightness)
#####IMPORT THE TRAINED MODEL#####
model = load_model('my_model.h5')
os.environ['TF_XLA_FLAGS'] = '--tf_xla_enable_xla_devices'
def grayscale(img):
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
return img
def equalize(img):
img = cv2.equalizeHist(img)
return img
def preprocessing(img):
img = grayscale(img)
img = equalize(img)
img = img / 255
return img
def getCalssName(classNo):
if classNo == 0:
return 'Speed Limit 20 km/h'
elif classNo == 1:
return 'Speed Limit 30 km/h'
.......
.......
elif classNo == 40:
return 'Roundabout mandatory'
elif classNo == 41:
return 'End of no passing'
elif classNo == 42:
return 'End of no passing by vechiles over 3.5 metric tons'
while True:
# READ IMAGE
success, imgOrignal = cap.read()
# PROCESS IMAGE
img = np.asarray(imgOrignal)
img = cv2.resize(img, (32, 32))
img = preprocessing(img)
cv2.imshow("Processed Image", img)
img = img.reshape(1, 32, 32, 1)
cv2.putText(imgOrignal, "CLASS: ", (20, 35), font,
0.75, (0, 0, 255), 2, cv2.LINE_AA)
cv2.putText(imgOrignal, "PROBABILITY: ", (20, 75),
font, 0.75, (0, 0, 255), 2, cv2.LINE_AA)
# PREDICT IMAGE
predictions = model.predict(img)
classIndex = model.predict_classes(img)
probabilityValue = np.amax(predictions)
if probabilityValue > threshold:
# print(getCalssName(classIndex))
cv2.putText(imgOrignal, str(classIndex) + " " + str(getCalssName(classIndex)),
(120, 35), font, 0.75, (0, 0, 255), 2, cv2.LINE_AA)
cv2.putText(imgOrignal, str(round(probabilityValue * 100, 2)) + "%",
(180, 75), font, 0.75, (0, 0, 255), 2, cv2.LINE_AA)
cv2.imshow("Result", imgOrignal)
if cv2.waitKey(1) and 0xFF == ord('q'):
"break"
cv2.waitkey(0) == ord(q)
The error is
2021-08-29 18:34:31.841473: W tensorflow/stream_executor/platform/default/dso_loader.cc:60] Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll not found 2021-08-29 18:34:31.843330: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine. 2021-08-29 18:34:46.621957: I tensorflow/compiler/jit/xla_cpu_device.cc:41] Not creating XLA devices, tf_xla_enable_xla_devices not set 2021-08-29 18:34:46.626059: W tensorflow/stream_executor/platform/default/dso_loader.cc:60] Could not load dynamic library 'nvcuda.dll'; dlerror: nvcuda.dll not found 2021-08-29 18:34:46.626801: W tensorflow/stream_executor/cuda/cuda_driver.cc:326] failed call to cuInit: UNKNOWN ERROR (303) 2021-08-29 18:34:46.634015: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:169] retrieving CUDA diagnostic information for host: CHOWDHURY-JOY-LPTP 2021-08-29 18:34:46.634852: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:176] hostname: CHOWDHURY-JOY-LPTP 2021-08-29 18:34:46.641932: 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. 2021-08-29 18:34:46.644266: I tensorflow/compiler/jit/xla_gpu_device.cc:99] Not creating XLA devices, tf_xla_enable_xla_devices not set
Upvotes: 1
Views: 1100
Reputation:
These warnings occurred as CuDNN.dll
is not found (which is used for running on GPU)
You can surpass these warnings using below code:
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
Please check this similar resolved issue for more details.
Upvotes: 1