Created
April 5, 2019 11:20
-
-
Save sam-thecoder/de983a5bc4e0cb047e7789721d5550bb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
train_images = os.listdir('data/train') | |
train_images[:10] | |
>>> | |
['cat.4213.jpg', | |
'cat.7203.jpg', | |
'dog.8250.jpg', | |
'dog.7907.jpg', | |
'dog.2318.jpg', | |
'cat.6480.jpg', | |
'dog.7973.jpg', | |
'dog.2225.jpg', | |
'dog.611.jpg', | |
'dog.5955.jpg'] | |
train_images_data = [] | |
train_images_labels = [] | |
random.shuffle(train_images) | |
for image in tqdm(train_images): | |
image_data = cv2.imread('data/train/' + image) | |
#Convert to GrayScale | |
gray = cv2.cvtColor(image_data, cv2.COLOR_BGR2GRAY) | |
#convert color from BGR to RGB | |
#image_data = cv2.cvtColor(image_data, cv2.COLOR_BGR2RGB) | |
image_data = cv2.resize(gray, (64, 64)) | |
#turn to only borders | |
image_data = cv2.Canny(image_data, 150, 150) | |
train_images_data.append(image_data) | |
train_images_data.append(image_data[:, ::-1]) #flipped image | |
if image.startswith('cat'): | |
train_images_labels.append(0) | |
train_images_labels.append(0) | |
else: | |
train_images_labels.append(1) | |
train_images_labels.append(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment