{"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\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\nimport cv2\nimport matplotlib.pyplot as plt\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,"_uuid":"06de54d4644e4dcf9f15b02ff352b78b9c56a6d1"},"cell_type":"code","source":"x1=(os.listdir(\"../input/train\"))\n\nimage=[]\ncatg=[]\n\nfor x in range(0,5000):\n   image.append(os.path.join(\"../input/train/\"+x1[x]))\n   catg.append(x1[x][:3])\ndata=pd.DataFrame()\ndata['image']=image\ndata['catg']=catg\ndata","execution_count":null,"outputs":[]},{"metadata":{"_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","trusted":true,"scrolled":true},"cell_type":"code","source":"#eda\ndata.catg.value_counts()\nfor x in data:\n    print(x.dtype)\n    img=cv2.imread(x,1)\n    img=cv2.cvtColor(img,cv2.COLOR_BGR2YUV_YV12)\n    plt.imshow(img)\n    break","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"bb8f18567b9fae4b16c93dbf5bc9f22d9a3fc60a"},"cell_type":"code","source":"#preparing data x and y\ny=pd.get_dummies(data.catg)\nX_train=[]\nfor x in data.image:\n        t=cv2.resize(cv2.imread(x,1),(224,224))\n        X_train.append(t)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"217e6cd4e07130fde9052fa2697d4c10fcbaa749"},"cell_type":"code","source":"X_train=np.array(X_train)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"20b1cdba0dbb1730743bf0465a26000310f51a58"},"cell_type":"code","source":"X_train.shape","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"f9a1fea5aabbe282c178cf13850dabe41077c97e"},"cell_type":"code","source":"x=np.ones((25000,250,250,3))\nfor y in range(0,25000):\n    x[y]=X_train[y]\n    \n    \n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"0daf1bf666b68991318e83a1a9f860865337feeb"},"cell_type":"code","source":"from keras.applications.imagenet_utils import preprocess_input\nplt.imshow(X_train[0])\nimage = np.expand_dims(X_train[0], axis=0)\nimage = preprocess_input(image)\nimage.shape","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"d03da7d2247d7d25c377b23bb3a51054d0961a72","scrolled":false},"cell_type":"code","source":"#training of data\nimport keras\nfrom keras.applications import VGG16\nfrom keras.models import Sequential\nfrom keras.layers import Dense,Flatten,Conv2D\n\nmodel=Sequential()\nmodel.add(VGG16(include_top=False,input_shape=(224,224,3)))\n#model.add(Conv2D(32,(3,3),padding='valid',input_shape=(250,250,3)))\nmodel.add(Flatten())\nmodel.add(Dense(2,activation=\"softmax\"))\nmodel.layers[0].trainable=True\n\nmodel.compile(optimizer=\"rmsprop\",loss=keras.losses.categorical_crossentropy,metrics=['accuracy'])\n\nmodel.fit(X_train,y,batch_size=30,epochs=2,verbose=1)\n\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"9b79c00a3365147fade07fd5b9e096a25fc89bea"},"cell_type":"code","source":"#plt.imshow(pre[0])\nfrom keras.applications.vgg16 import decode_predictions\nP = decode_predictions(pre)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"75cdda91fb82316c742f93bf24592430b6e61883"},"cell_type":"code","source":"model.summary()","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"name":"python","version":"3.6.6","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"}},"nbformat":4,"nbformat_minor":1}