{"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 \n%matplotlib inline\nimport matplotlib.pyplot as plt\nimport cv2\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\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\n\nimport os\nprint(os.listdir(\"../input\"))\n\n# Any results you write to the current directory are saved as output.","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"%ls '../input/'\nlabels=pd.read_csv('../input/labels.csv')\ntest=pd.read_csv('../input/sample_submission.csv')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"path=labels['id']\ntarget1=labels['breed']\ntestpath=test['id']","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"target=target1.append(target1)\ntarget=target.append(target)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"from keras.preprocessing.image import load_img,img_to_array\nimage_train1=[]\nfor x in path:\n    y=cv2.imread('../input/train/'+x+'.jpg')\n    y=cv2.resize(y,(64,64))\n    y=cv2.GaussianBlur(y,(5,5),0)\n    y=cv2.cvtColor(y, cv2.COLOR_RGB2GRAY)\n    image_train1.append(img_to_array(y))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"image_test=[]\nfor x in testpath:\n    y=cv2.imread('../input/test/'+x+'.jpg')\n    y=cv2.resize(y,(64,64))\n    y=cv2.GaussianBlur(y,(5,5),0)\n    y=cv2.cvtColor(y, cv2.COLOR_RGB2GRAY)\n    image_test.append(img_to_array(y))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"image_train=np.array(image_train1)\nimage_test=np.array(image_test)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"image_train.shape","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"image_train=np.append(image_train,image_train,0)\nimage_train=np.append(image_train,image_train,0)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"image_train.shape","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"target_all=pd.get_dummies(target,sparse=True)\ntarget=np.asarray(target_all)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"from keras.layers import Dense,Dropout,Flatten,Conv2D,MaxPool2D,AvgPool2D\nfrom sklearn.model_selection import train_test_split as tts\nxtrain,xtest,ztrain,ztest=tts(image_train,target,train_size=0.8)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"from keras.models import Sequential\nfrom keras.layers import MaxPool2D,AvgPool2D\nmodel=Sequential()\nmodel.add(Conv2D(filters=64,kernel_size=(3,3),activation='relu',input_shape=(64,64,1)))\nmodel.add(MaxPool2D(pool_size=(2,2)))\nmodel.add(Dropout(0.2))\nmodel.add(Conv2D(filters=32,kernel_size=(3,3),activation='relu'))\nmodel.add(MaxPool2D(pool_size=(2,2)))\nmodel.add(Conv2D(filters=16,kernel_size=(3,3),activation='relu'))\nmodel.add(MaxPool2D(pool_size=(2,2)))\nmodel.add(Dropout(0.2))\nmodel.add(Flatten())\nmodel.add(Dense(300, activation = \"relu\"))\nmodel.add(Dropout(0.2))\nmodel.add(Dense(200, activation = \"relu\"))\nmodel.add(Dropout(0.2))\nmodel.add(Dense(120, activation = \"softmax\"))\nfrom keras.preprocessing.image import ImageDataGenerator\ndata=ImageDataGenerator(height_shift_range=0.1,width_shift_range=0.1,rotation_range=0.1,zoom_range=0.1)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"model.compile(loss='categorical_crossentropy',optimizer='rmsprop',metrics=['accuracy'])","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"history=model.fit_generator(data.flow(xtrain,ztrain,batch_size=3000),steps_per_epoch=20,epochs=10,validation_data=[xtest,ztest])","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","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}