Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"OSError: [Errno 12] Cannot allocate memory" when load image with fit_generator #10

Open
wenbotse opened this issue Oct 16, 2018 · 1 comment

Comments

@wenbotse
Copy link

OSError: [Errno 12] Cannot allocate memory.

27 def train_data_generator():
28 image_data_list = []
29 label = []
30 progress = 0
31 pos_file_list = os.listdir(pos_image_path)
32 neg_file_list = os.listdir(neg_image_path)
33 while True:
34 for i in range(sample_num):
35 url = os.path.join(pos_image_path +'/' + pos_file_list[i])
36 image = load_img(url, target_size=(128, 128))
37 image_data_list.append(img_to_array(image))
38 label.append(1)
39 image.close()
40 progress = progress + 1
41 url = os.path.join(neg_image_path + '/' + neg_file_list[i])
42 image = load_img(url, target_size=(128, 128))
43 image_data_list.append(img_to_array(image))
44 label.append(0)
45 image.close()
46 progress = progress + 1
47 if progress == fit_gen_batch_size:
48 img_data = np.array(image_data_list)
49 img_data = img_data.astype('float32')
50 img_data /= 255
51 #print("generator image_data=",len(img_data),"label=",len(label))
52 yield img_data, label
53 label.clear()
54 img_data[:]=0
55 image_data_list.clear()
56 progress = 0
57 gc.collect()

@wenbotse
Copy link
Author

Is there some code cause memory leak ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant