-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTensorflow_data.py
More file actions
140 lines (64 loc) · 1.63 KB
/
Tensorflow_data.py
File metadata and controls
140 lines (64 loc) · 1.63 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/usr/bin/env python
# coding: utf-8
# In[7]:
import numpy as np
import matplotlib.pyplot as plt
import os
# In[2]:
import cv2
# In[3]:
DATADIR = "/home/hrishikesh/tensorflow/PetImages"
# In[4]:
DATADIR
# In[20]:
CATAGORIES = ["Dog","Cat"]
# In[22]:
for category in CATAGORIES:
path = os.path.join(DATADIR, category)
for img in os.listdir(path):
img_array = cv2.imread(os.path.join(path,img), cv2.IMREAD_GRAYSCALE)
plt.imshow(img_array,cmap="gray")
plt.show()
break
break
# In[10]:
print(img_array.shape)
# In[15]:
IMG_SIZE = 50
new_array = cv2.resize(img_array, (IMG_SIZE, IMG_SIZE))
plt.imshow(new_array,cmap="gray")
# In[16]:
training_data = []
# In[28]:
CATAGORIES = ["Dog","Cat"]
def create_training_data():
for category in CATAGORIES:
path = os.path.join(DATADIR, category)
class_num = CATAGORIES.index(category)
for img in os.listdir(path):
try:
img_array = cv2.imread(os.path.join(path,img), cv2.IMREAD_GRAYSCALE)
new_array = cv2.resize(img_array, (IMG_SIZE, IMG_SIZE))
training_data.append([new_array,class_num])
except Exception as e:
pass
create_training_data()
# In[29]:
print(len(training_data))
# In[30]:
import random
# In[31]:
random.shuffle(training_data)
# In[34]:
for sample in training_data:
print(sample[1])
# In[35]:
X = []
y = []
# In[36]:
for features,label in training_data:
X.append(features)
y.append(label)
# In[37]:
X = np.array(X).reshape(-1, IMG_SIZE, IMG_SIZE, 1)
# In[ ]: