-
Notifications
You must be signed in to change notification settings - Fork 0
/
p1.py
48 lines (38 loc) · 1.33 KB
/
p1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import cv2
"""
import numpy as np
import os
from random import shuffle
from tqdm import tqdm
TRAIN_DIR = "D:\Python tutorial videos\DATA SETS\\train"
TEST_DIR = "D:\Python tutorial videos\DATA SETS\\test1"
IMG_SIZE = 50
LR = 1e-3
MODEL_NAME = "cats vs dogs-{}-{}.model".format(LR, "2conv-basic")
# helper functions
def label_image(img):
word_label = img.split(".")[-3]
if word_label == "cat": return [1, 0]
elif word_label == "dog": return [0, 1]
def create_train_data():
training_data = []
for img in tqdm(os.listdir(TRAIN_DIR)):
label = label_image(img)
path = os.path.join(TRAIN_DIR, img)
img = cv2.resize(cv2.imread(path, cv2.IMREAD_GRAYSCALE), (IMG_SIZE, IMG_SIZE))
training_data.append([np.array(img), np.array(label)])
shuffle(training_data)
np.save("training_data.npy", training_data)
return training_data
# test_data
def process_test_data():
testing_data = []
for img in tqdm(os.listdir(TEST_DIR)):
path = os.path.join(TEST_DIR, img)
img_num = img.split(".")[0]
img = cv2.resize(cv2.imread(path, cv2.IMREAD_GRAYSCALE), (IMG_SIZE, IMG_SIZE))
testing_data.append([np.array(img), img_num])
np.save("test_data.npy", testing_data)
return testing_data
train_data = create_train_data()
"""