У меня есть этот кусок кода, который аварийно завершает работу (перезапускает ядро) после 2 циклов в ноутбуке jupyter. Я подозреваю, что, возможно, это проблема с памятью и необходимо очищать память после каждого l oop. Я включил код ниже. Моя машина имеет 4 Гб памяти и двухъядерный процессор. Кто-нибудь сможет помочь в этом вопросе.
Пожалуйста, найдите код ниже
@jit(nopython=True)
def square(list):
return [i ** 2 for i in list]
#Extracting images from the faked videos no optimization. opencv4
for i in tqdm(range(0,100000,5),desc ='Images Created'):
if str(df2['original'][i]).endswith(".mp4"):
fake_frame_list = []
orgi_frame_list = []
cap1 = cv2.VideoCapture('/media/michael/extHDD/Kaggle/DeepFAke/DF_all/{}'.format(df2['fake_name'][i]))
while(cap1.isOpened()):
ret1, frame1 = cap1.read()
if ret1 == False:
break
fake_frame_list.append(frame1) # list of all the frames in fake video
cap1.release()
cap2 = cv2.VideoCapture('/media/michael/extHDD/Kaggle/DeepFAke/DF_all/{}'.format(df2['original'][i]))
while(cap2.isOpened()):
ret2, frame2 = cap2.read()
if ret2 == False:
break
orgi_frame_list.append(frame2) # list of all the frames in original video
cap2.release()
if len(orgi_frame_list)==len(fake_frame_list): #Check if real and fake videos have the same length (frames)
d1 = []
for c in range(len(fake_frame_list)):#to check if there is a difference in the images
d1.append(fake_frame_list[c]-orgi_frame_list[c])
list_of_dis = []
for k in tqdm(range(len(d1)),desc = 'Frames Extracted',leave = False):
sum_dist = []
for j in tqdm(range(3),desc = 'Dim Distance Added',leave = False):
s = np.sum(square(d1[k][:,:,j].reshape(-1)))
sum_dist.append(s) # square each value in the resulting list (dimenstion)
distance = np.sum(sum_dist) # adding the total value for each dimension to a list
list_of_dis.append(np.round(np.sqrt(distance))) # Sum the values to get the total
#squared values of residual images
max_value = max(list_of_dis)
max_index = list_of_dis.index(max_value)
cv2.imwrite('/home/michael/DFDC_New/FakeTrain/frame_'+str(df2['fake_name'][i])[:-4]+'.jpg',
fake_frame_list[max_index])
cv2.destroyAllWindows()
Спасибо за помощь.
Спасибо и наилучшими пожеланиями
Майкл