-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
296 additions
and
166 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
148 changes: 148 additions & 0 deletions
148
.ipynb_checkpoints/05_Convolutional_Neural_Networks-checkpoint.ipynb
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import os\n", | ||
"import cv2\n", | ||
"import numpy as np\n", | ||
"from tqdm import tqdm\n", | ||
"\n", | ||
"REBUILD_DATA = True" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"REBUILD_DATA = True # set to true to one once, then back to false unless you want to change something in your training data.\n", | ||
"\n", | ||
"class DogsVSCats():\n", | ||
" IMG_SIZE = 50\n", | ||
" CATS = \"/Users/Mac/Downloads/kagglecatsanddogs/PetImages/Cat\"\n", | ||
" DOGS = \"/Users/Mac/Downloads/kagglecatsanddogs/PetImages/Dog\"\n", | ||
" TESTING = \"PetImages/Testing\"\n", | ||
" LABELS = {CATS: 0, DOGS: 1}\n", | ||
" training_data = []\n", | ||
"\n", | ||
" catcount = 0\n", | ||
" dogcount = 0\n", | ||
"\n", | ||
" def make_training_data(self):\n", | ||
" for label in self.LABELS:\n", | ||
" print(label)\n", | ||
" for f in tqdm(os.listdir(label)):\n", | ||
" if \"jpg\" in f:\n", | ||
" try:\n", | ||
" path = os.path.join(label, f)\n", | ||
" img = cv2.imread(path, cv2.IMREAD_GRAYSCALE)\n", | ||
" img = cv2.resize(img, (self.IMG_SIZE, self.IMG_SIZE))\n", | ||
" self.training_data.append([np.array(img), np.eye(2)[self.LABELS[label]]]) # do something like print(np.eye(2)[1]), just makes one_hot \n", | ||
" #print(np.eye(2)[self.LABELS[label]])\n", | ||
"\n", | ||
" if label == self.CATS:\n", | ||
" self.catcount += 1\n", | ||
" elif label == self.DOGS:\n", | ||
" self.dogcount += 1\n", | ||
"\n", | ||
" except Exception as e:\n", | ||
" pass\n", | ||
" #print(label, f, str(e))\n", | ||
"\n", | ||
" np.random.shuffle(self.training_data)\n", | ||
" np.save(\"training_data.npy\", self.training_data)\n", | ||
" print('Cats:',dogsvcats.catcount)\n", | ||
" print('Dogs:',dogsvcats.dogcount)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stderr", | ||
"output_type": "stream", | ||
"text": [ | ||
" 1%| | 73/12501 [00:00<00:17, 727.44it/s]" | ||
] | ||
}, | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"/Users/Mac/Downloads/kagglecatsanddogs/PetImages/Cat\n" | ||
] | ||
}, | ||
{ | ||
"name": "stderr", | ||
"output_type": "stream", | ||
"text": [ | ||
"100%|██████████| 12501/12501 [02:44<00:00, 75.80it/s]\n", | ||
" 0%| | 8/12501 [00:00<02:49, 73.78it/s]" | ||
] | ||
}, | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"/Users/Mac/Downloads/kagglecatsanddogs/PetImages/Dog\n" | ||
] | ||
}, | ||
{ | ||
"name": "stderr", | ||
"output_type": "stream", | ||
"text": [ | ||
"100%|██████████| 12501/12501 [02:22<00:00, 87.59it/s] \n" | ||
] | ||
}, | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Cats: 12476\n", | ||
"Dogs: 12470\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"if REBUILD_DATA:\n", | ||
" dogsvcats = DogsVSCats()\n", | ||
" dogsvcats.make_training_data()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.6.8" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
Oops, something went wrong.