I am working on the Computer Vision Deep Learning Program and I have encountered what looks to me a very unspecific error message that does not give any hints whatsoever.
Process finished with exit code -1073740791 (0xC0000409)
In search of the solution I found out that the code works perfectly fine with the CPU, although it takes much longer to process.
When debugging, I found out that the error is thrown at the return of the model.predict().
Searching the web I couldn't find a relevant problem and the solution that would work.
Code used:
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Dropout
from tensorflow.keras.preprocessing import image
from tensorflow.keras.applications.vgg16 import VGG16
from sklearn.metrics import accuracy_score
import numpy as np
import pandas as pd
from tqdm import tqdm
import cv2
import math
import os
from glob import glob
from scipy import stats as s
def dl_training():
base_model = VGG16(weights='imagenet', include_top=False)
# defining the model architecture
model = Sequential()
model.add(Dense(1024, activation='relu', input_shape=(25088,)))
model.add(Dropout(0.5))
model.add(Dense(512, activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(256, activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(128, activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(64, activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(32, activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(2, activation='softmax'))
# loading the trained weights
model.load_weights("weights_test.hdf5")
# compiling the model
model.compile(loss='categorical_crossentropy', optimizer='Adam', metrics=['accuracy'])
# getting the test list
f = open("Anomaly_Test_2class.txt", "r")
temp = f.read()
videos = temp.split('\n')
del temp
# creating the dataframe
test = pd.DataFrame()
test['video_name'] = videos
test = test[:-1]
test_videos = test['video_name']
test.head()
# creating the tags
train = pd.read_csv('train_new_2class.csv')
y = pd.get_dummies(train['class'])
predict = []
actual = []
# for loop to extract frames from each test video
for i in tqdm(range(test_videos.shape[0])):
count = 0
videoFile = test_videos[i]
cap = cv2.VideoCapture(
'Videos/' + videoFile) # capturing the video from the given path
# print('Videos/' + videoFile)
frameRate = cap.get(5) # frame rate
# removing all other files from the temp folder
files = glob('temp/*')
for f in files:
os.remove(f)
while cap.isOpened():
frameId = cap.get(1) # current frame number
ret, frame = cap.read()
if not ret:
break
if frameId % math.floor(frameRate) == 0:
# storing the frames of this particular video in temp folder
filename = 'temp/' + "_frame%d.jpg" % count
count += 1
cv2.imwrite(filename, frame)
cap.release()
# reading all the frames from temp folder
images = glob("temp/*.jpg")
prediction_images = []
for j in range(len(images)):
img = image.load_img(images[j], target_size=(224, 224, 3))
img = image.img_to_array(img)
img = img / 255
prediction_images.append(img)
# converting all the frames for a test video into numpy array
prediction_images = np.array(prediction_images)
# extracting features using pre-trained model
prediction_images = base_model.predict(prediction_images)
# converting features in one dimensional array
prediction_images = prediction_images.reshape(prediction_images.shape[0], 7 * 7 * 512)
# predicting tags for each array
prediction = model.predict_classes(prediction_images)
# appending the mode of predictions in predict list to assign the tag to the video
predict.append(y.columns.values[s.mode(prediction)[0][0]])
# print("\n" + "Prediction: " + y.columns.values[s.mode(prediction)[0][0]])
# appending the actual tag of the video
if videoFile.split('/')[0].split('_')[0] == "Testing":
actual.append("Normal_Videos_event")
# print("Actual Class: Normal_Videos_event")
else:
actual.append(videoFile.split('/')[0])
# print("Actual Class: " + videoFile.split('/')[0])
# checking the accuracy of the predicted tags
accuracy = accuracy_score(predict, actual) * 100
print("Accuracy: %f" % accuracy)
This error also occurs when executing any other code that has a predict function in it. I should clarify that the GPU is connected and when testing using tf.test.is_built_with_cuda() and tf.test.is_gpu_available() is positive.
Also, one more thing worth mentioning is that I cannot fetch the documentation of the predict function.
Is this intended?
Studying this code from: https://www.analyticsvidhya.com/blog/2019/09/step-by-step-deep-learning-tutorial-video-classification-python/
Using Python 3.7, PyCharm, tensorflow-gpu 2.1.0, keras 2.3.1, numpy 1.20.1, scikit-learn 0.24.1, pandas 1.2.2, tqdm 4.56.2, scipy 1.4.1, opencv 4.5.1.48, pip 21.0.1, setuptools 53.0.0, six 1.15.0
User contributions licensed under CC BY-SA 3.0