{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load in \nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nimport matplotlib.pyplot as plt\n# Input data files are available in the \"../input/\" directory.\n# For example, running this (by clicking run or pressing Shift+Enter) will list the files in the input directory\nimport os\n\nprint(os.listdir(\"../input\"))\n# Any results you write to the current directory are saved as output.","execution_count":null,"outputs":[]},{"metadata":{"_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","trusted":true},"cell_type":"code","source":"\nimport pandas as pd\nimport numpy as np\nimport seaborn as sns\nimport matplotlib\nimport os\nfrom shutil import copyfile\nimport matplotlib.pyplot as plt\n#%matplotlib inline","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"labels = pd.read_csv('../input/labels.csv')\n\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"\nlabels_dict = {i:j for i,j in zip(labels['id'],labels['breed'])}\nclasses = set(labels_dict.values())\nimages = [f for f in os.listdir('train')]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"\nif  not os.path.exists('training_images'):\n        os.makedirs('training_images')\n\nif  not os.path.exists('validation_images'):\n    os.makedirs('validation_images')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"os.chdir('training_images')\nfor curClass in classes:    \n    if  not os.path.exists(curClass):\n        os.makedirs(curClass)\n        #os.rmdir(curClass)\n\nos.chdir('../validation_images')\nfor curClass in classes:    \n    if  not os.path.exists(curClass):\n        os.makedirs(curClass)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"os.chdir('..')\ncount = 0 \ndestination_directory = 'training_images/'\nfor item in images:\n    if count >7999:\n        destination_directory = 'validation_images/'\n    filekey = os.path.splitext(item)[0]\n    if  not os.path.exists(destination_directory+labels_dict[filekey]+'/'+item):\n        copyfile('train/'+item, destination_directory+labels_dict[filekey]+'/'+item)\n    print(labels_dict[filekey])\n    count +=1","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"from keras.preprocessing.image import ImageDataGenerator, array_to_img, img_to_array, load_img\n\ndatagen = ImageDataGenerator(\n        rotation_range=50,\n        width_shift_range=0.3,\n        height_shift_range=0.2,\n        shear_range=0.3,\n        zoom_range=0.3,\n        horizontal_flip=True,\n        fill_mode='nearest')\n\nimg = load_img('training_images/afghan_hound/0d5a88f0ab2db8d34b533c69768135e8.jpg') \nx = img_to_array(img)\nx = x.reshape((1,) + x.shape)\n\ni = 0\nfor batch in datagen.flow(x, batch_size=1,\n                          save_to_dir='preview', save_prefix='dog_breed', save_format='jpeg'):\n    i += 1\n    if i > 20:\n        break  # otherwise the generator would loop indefinitely","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"name":"python","version":"3.6.4","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"}},"nbformat":4,"nbformat_minor":1}