diff --git a/.ipynb_checkpoints/05-checkpoint.ipynb b/.ipynb_checkpoints/05-checkpoint.ipynb deleted file mode 100644 index 6a73cfc..0000000 --- a/.ipynb_checkpoints/05-checkpoint.ipynb +++ /dev/null @@ -1,83 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 7, - "metadata": {}, - "outputs": [], - "source": [ - "import os\n", - "import cv2\n", - "import numpy as np\n", - "from tqdm import tqdm\n", - "\n", - "REBUILD_DATA = True\n", - "\n", - "class DogVCCats():\n", - " IMG_SIZE = 50\n", - " CATS = 'PetImages/Cat'\n", - " DOGS = 'PetImages/Dog'\n", - " LABELS = {CATS: 0, DOGS: 1}\n", - " \n", - " training_data = []\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", - " 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]]])\n", - " \n", - " if Label == self.CATS:\n", - " self.catcount += 1\n", - " elif label == self.DOGS:\n", - " self.dogcount += 1\n", - " except Exception as e:\n", - " pass\n", - " #print(str(e))\n", - " np.random.shuffle(self.training_data)\n", - " np.save('training_data.npy', self.training_data)\n", - " print('Cats: ', self.catcount)\n", - " print('Dogs: ', self.dogcount)\n", - " \n", - "\n", - "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 -} diff --git a/.ipynb_checkpoints/05_Convolutional_Neural_Networks-checkpoint.ipynb b/.ipynb_checkpoints/05_Convolutional_Neural_Networks-checkpoint.ipynb new file mode 100644 index 0000000..4c5113f --- /dev/null +++ b/.ipynb_checkpoints/05_Convolutional_Neural_Networks-checkpoint.ipynb @@ -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 +} diff --git a/05.ipynb b/05.ipynb deleted file mode 100644 index 6a73cfc..0000000 --- a/05.ipynb +++ /dev/null @@ -1,83 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 7, - "metadata": {}, - "outputs": [], - "source": [ - "import os\n", - "import cv2\n", - "import numpy as np\n", - "from tqdm import tqdm\n", - "\n", - "REBUILD_DATA = True\n", - "\n", - "class DogVCCats():\n", - " IMG_SIZE = 50\n", - " CATS = 'PetImages/Cat'\n", - " DOGS = 'PetImages/Dog'\n", - " LABELS = {CATS: 0, DOGS: 1}\n", - " \n", - " training_data = []\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", - " 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]]])\n", - " \n", - " if Label == self.CATS:\n", - " self.catcount += 1\n", - " elif label == self.DOGS:\n", - " self.dogcount += 1\n", - " except Exception as e:\n", - " pass\n", - " #print(str(e))\n", - " np.random.shuffle(self.training_data)\n", - " np.save('training_data.npy', self.training_data)\n", - " print('Cats: ', self.catcount)\n", - " print('Dogs: ', self.dogcount)\n", - " \n", - "\n", - "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 -} diff --git a/05_Convolutional_Neural_Networks.ipynb b/05_Convolutional_Neural_Networks.ipynb new file mode 100644 index 0000000..4c5113f --- /dev/null +++ b/05_Convolutional_Neural_Networks.ipynb @@ -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 +} diff --git a/training_data.npy b/training_data.npy new file mode 100644 index 0000000..f3f6030 Binary files /dev/null and b/training_data.npy differ