Skip to content

Commit 8cb60d6

Browse files
Create python mask training
please merge my code
1 parent 86a33e3 commit 8cb60d6

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

python mask training

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import cv2
2+
import numpy as np
3+
import os
4+
import random
5+
import pickle
6+
t_d = []
7+
directory = "C:\\Users\\AYUSH MISHRA\\Desktop"
8+
categories = ["with_mask","without_mask"]
9+
for i in categories :
10+
path = os.path.join(directory,i)
11+
c_n = categories.index(i)
12+
for p in os.listdir(path):
13+
14+
img = cv2.imread(os.path.join(path,p))
15+
16+
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
17+
img_resize= cv2.resize(gray,(224,224))
18+
t_d.append([img_resize, c_n])
19+
20+
21+
random.shuffle(t_d)
22+
print(len(t_d))
23+
label = []
24+
feature = []
25+
for f in t_d :
26+
label.append(f)
27+
feature.append(f)
28+
label = label/255.0
29+
labels = np.array(label).reshape((-1,224,224,3))
30+
features = np.array(feature)
31+
pickle_o = open("labels.pickle","wb")
32+
pickle.dump(labels,pickle_o)
33+
pickle_o.close()
34+
pickle_o = open("features.pickle","wb")
35+
pickle.dump(features,pickle_o)
36+
pickle_o.close()
37+
print(labels.shape,features.shape) # shape of the training data
38+
39+
40+
41+

0 commit comments

Comments
 (0)