{"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\n\nimport os\nprint(os.listdir(\"../input\"))\nprint(\"the  train_image has picture： %d \\nthe test_image has picture:%d\" % (len(os.listdir('../input/train_images')),\n                                                                           len(os.listdir('../input/test_images'))))\n\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":"#import matplotlib.pyplot as plt\nfrom keras.utils.np_utils import to_categorical\nimport cv2\n\ntrain_data=pd.read_csv(\"../input/train.csv\")\ntrain_path='../input/train_images'\nlabels=train_data['diagnosis']\nall_labels=to_categorical(labels)\n\nimages=[]\nlabels=[]\ndef generator_data():\n    for  i,l in zip(train_data['id_code'],all_labels):\n        image_data=cv2.imread(os.path.join(train_path,i+'.png'))\n        image_data=cv2.resize(image_data,(224,224))\n        image_data =image_data / 255.\n        images.append(image_data)\n        labels.append(l)\n    return  images,labels \n\ntrain_data,train_labels=generator_data()\ntrain_data=np.array(train_data)\ntrain_labels=np.array(train_labels)\n\n                \n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"del images\ndel labels","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"from keras import layers\nfrom keras  import models\n\nfrom keras.layers import LeakyReLU\nmodel=models.Sequential()\nmodel.add(layers.Conv2D(64,(2,2),activation='relu',input_shape=(224,224,3)))\n#model.add(LeakyReLU(alpha=0.05))\n#model.add(layers.Dropout(0.2))\nmodel.add(layers.MaxPooling2D(2,2))\n\nmodel.add(layers.Conv2D(128,(2,2),activation='relu'))\n#model.add(LeakyReLU(alpha=0.05))\n#model.add(layers.Dropout(0.2))\nmodel.add(layers.MaxPooling2D(2,2))\n\nmodel.add(layers.Conv2D(128,(2,2),activation='relu'))\n#model.add(LeakyReLU(alpha=0.05))\nmodel.add(layers.MaxPooling2D(2,2))\n#model.add(layers.Dropout(0.2))\n\nmodel.add(layers.Flatten())\nmodel.add(layers.Dense(512,activation='relu'))\n#model.add(layers.Dropout(0.2))\nmodel.add(layers.Dense(5,activation='softmax'))\nmodel.summary()\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"\nfrom keras.callbacks import Callback, ModelCheckpoint\nmodel.compile(optimizer='rmsprop',loss='categorical_crossentropy',metrics=['acc'])\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"history=model.fit(train_data,train_labels,batch_size=32,epochs=15,class_weight='auto',validation_split=0.15)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"test_data=pd.read_csv('../input/test.csv')\ntest_path='../input/test_images'\n\n\ntarget=[]\nfor  i in test_data['id_code']:\n    test_image=cv2.imread(os.path.join(test_path,i+'.png'))\n    test_image=cv2.resize(test_image,(224,224))\n    test_image=test_image/255.\n    test_image=test_image.reshape((1,)+test_image.shape)\n    target.append(np.argmax(model.predict(test_image)))\n\ntarget=np.array(target)\ntest_data['diagnosis']=target","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"print(test_data['diagnosis'])","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"test_data.to_csv('submission.csv',index=False)","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}