Skip to content

Instantly share code, notes, and snippets.

@zhigang1992
Created January 19, 2018 08:58
Show Gist options
  • Save zhigang1992/f2d115fe28d0880d49d919bfd2b72d82 to your computer and use it in GitHub Desktop.
Save zhigang1992/f2d115fe28d0880d49d919bfd2b72d82 to your computer and use it in GitHub Desktop.
Learning/Lesson1/StateFarm.ipynb
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"metadata": {},
"cell_type": "markdown",
"source": "## Preprocess data"
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "%mkdir -p /data/statefarm/\n%pushd /data/statefarm/\n!kg download -c state-farm-distracted-driver-detection\n%popd",
"execution_count": null,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "%rm -r /root/statefarm\n%mkdir -p /root/statefarm\n!unzip -q /data/statefarm/driver_imgs_list.csv.zip -d /root/statefarm\n!unzip -q /data/statefarm/imgs.zip -d /root/statefarm\n!unzip -q /data/statefarm/sample_submission.csv.zip -d /root/statefarm",
"execution_count": null,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "from PIL import Image\nImage.open('/root/statefarm/train/c0/img_100026.jpg')",
"execution_count": null,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "from glob import glob\nimport numpy as np\nfrom os import path\nfrom os import makedirs\nfrom shutil import move\n\nshuffled = np.random.permutation(glob('/root/statefarm/train/*/*.jpg'))\nfor i in range(round(len(shuffled) * 0.3)):\n source = shuffled[i]\n target = source.replace('train', 'valid')\n targetdir = path.dirname(target)\n if not path.exists(targetdir):\n makedirs(targetdir)\n move(source, target)",
"execution_count": null,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "from keras.preprocessing import image\ntrain_batch = image.ImageDataGenerator().flow_from_directory(\n '/root/statefarm/train/',\n target_size=(224, 224), \n batch_size=32\n)\nvalid_batch = image.ImageDataGenerator().flow_from_directory(\n '/root/statefarm/valid/', \n target_size=(224, 224),\n batch_size=32\n)",
"execution_count": 3,
"outputs": [
{
"output_type": "stream",
"text": "Found 15697 images belonging to 10 classes.\nFound 6727 images belonging to 10 classes.\n",
"name": "stdout"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "from keras.applications import VGG16\nfrom keras.models import Model\nfrom keras.layers import Convolution2D\nfrom keras.layers import Flatten\nfrom keras.layers import Dense\nfrom keras.layers import MaxPooling2D\n\n\ndef combine(layers):\n def combined(x):\n for l in layers:\n x = l(x)\n return x\n return combined\n\ndef Conv(num_filter, num_layer=1):\n return combine([Convolution2D(\n num_filter, \n 3,\n 3, \n activation='relu',\n border_mode='same'\n ) for i in range(num_layer)] + [\n MaxPooling2D(pool_size=(2, 2), strides=(2, 2))\n ])\n\nvgg = VGG16(include_top=True, input_shape=(224, 224, 3))\n\noutput = Dense(10, activation='softmax')(vgg.layers[-2].output)\n\n# for l in vgg.layers[:10]:\n# l.trainable = False\n \n# output = combine([\n# Conv(512, num_layer=3),\n# Conv(512, num_layer=3),\n# Flatten(),\n# Dense(10),\n# ])(vgg.layers[10].output)\n\n# output = combine([Flatten(), Dense(10)])(vgg.output)\n\nmodel = Model(vgg.input, output)\nmodel.summary()",
"execution_count": 5,
"outputs": [
{
"output_type": "stream",
"text": "____________________________________________________________________________________________________\nLayer (type) Output Shape Param # Connected to \n====================================================================================================\ninput_2 (InputLayer) (None, 224, 224, 3) 0 \n____________________________________________________________________________________________________\nblock1_conv1 (Convolution2D) (None, 224, 224, 64) 1792 input_2[0][0] \n____________________________________________________________________________________________________\nblock1_conv2 (Convolution2D) (None, 224, 224, 64) 36928 block1_conv1[0][0] \n____________________________________________________________________________________________________\nblock1_pool (MaxPooling2D) (None, 112, 112, 64) 0 block1_conv2[0][0] \n____________________________________________________________________________________________________\nblock2_conv1 (Convolution2D) (None, 112, 112, 128) 73856 block1_pool[0][0] \n____________________________________________________________________________________________________\nblock2_conv2 (Convolution2D) (None, 112, 112, 128) 147584 block2_conv1[0][0] \n____________________________________________________________________________________________________\nblock2_pool (MaxPooling2D) (None, 56, 56, 128) 0 block2_conv2[0][0] \n____________________________________________________________________________________________________\nblock3_conv1 (Convolution2D) (None, 56, 56, 256) 295168 block2_pool[0][0] \n____________________________________________________________________________________________________\nblock3_conv2 (Convolution2D) (None, 56, 56, 256) 590080 block3_conv1[0][0] \n____________________________________________________________________________________________________\nblock3_conv3 (Convolution2D) (None, 56, 56, 256) 590080 block3_conv2[0][0] \n____________________________________________________________________________________________________\nblock3_pool (MaxPooling2D) (None, 28, 28, 256) 0 block3_conv3[0][0] \n____________________________________________________________________________________________________\nblock4_conv1 (Convolution2D) (None, 28, 28, 512) 1180160 block3_pool[0][0] \n____________________________________________________________________________________________________\nblock4_conv2 (Convolution2D) (None, 28, 28, 512) 2359808 block4_conv1[0][0] \n____________________________________________________________________________________________________\nblock4_conv3 (Convolution2D) (None, 28, 28, 512) 2359808 block4_conv2[0][0] \n____________________________________________________________________________________________________\nblock4_pool (MaxPooling2D) (None, 14, 14, 512) 0 block4_conv3[0][0] \n____________________________________________________________________________________________________\nblock5_conv1 (Convolution2D) (None, 14, 14, 512) 2359808 block4_pool[0][0] \n____________________________________________________________________________________________________\nblock5_conv2 (Convolution2D) (None, 14, 14, 512) 2359808 block5_conv1[0][0] \n____________________________________________________________________________________________________\nblock5_conv3 (Convolution2D) (None, 14, 14, 512) 2359808 block5_conv2[0][0] \n____________________________________________________________________________________________________\nblock5_pool (MaxPooling2D) (None, 7, 7, 512) 0 block5_conv3[0][0] \n____________________________________________________________________________________________________\nflatten (Flatten) (None, 25088) 0 block5_pool[0][0] \n____________________________________________________________________________________________________\nfc1 (Dense) (None, 4096) 102764544 flatten[0][0] \n____________________________________________________________________________________________________\nfc2 (Dense) (None, 4096) 16781312 fc1[0][0] \n____________________________________________________________________________________________________\ndense_2 (Dense) (None, 10) 40970 fc2[0][0] \n====================================================================================================\nTotal params: 134,301,514\nTrainable params: 134,301,514\nNon-trainable params: 0\n____________________________________________________________________________________________________\n",
"name": "stdout"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "from keras.optimizers import Adam\nfrom keras.optimizers import SGD\nsgd = SGD(lr=1e-4, decay=1e-6, momentum=0.9, nesterov=True)\nmodel.compile(sgd, loss='categorical_crossentropy', metrics=['accuracy'])\nmodel.fit_generator(\n train_batch,\n samples_per_epoch=train_batch.nb_sample, \n nb_epoch=5,\n validation_data=valid_batch,\n nb_val_samples=valid_batch.nb_sample\n)",
"execution_count": 6,
"outputs": [
{
"output_type": "stream",
"text": "Epoch 1/5\n15697/15697 [==============================] - 274s - loss: 0.3161 - acc: 0.9032 - val_loss: 0.0402 - val_acc: 0.9921\nEpoch 2/5\n15697/15697 [==============================] - 273s - loss: 0.0183 - acc: 0.9949 - val_loss: 0.0184 - val_acc: 0.9936\nEpoch 3/5\n15697/15697 [==============================] - 273s - loss: 0.0033 - acc: 0.9991 - val_loss: 0.0150 - val_acc: 0.9955\nEpoch 4/5\n15697/15697 [==============================] - 273s - loss: 3.0465e-04 - acc: 1.0000 - val_loss: 0.0146 - val_acc: 0.9955\nEpoch 5/5\n15697/15697 [==============================] - 273s - loss: 1.3703e-04 - acc: 1.0000 - val_loss: 0.0171 - val_acc: 0.9941\n",
"name": "stdout"
},
{
"output_type": "execute_result",
"execution_count": 6,
"data": {
"text/plain": "<keras.callbacks.History at 0x7f7cb156ba90>"
},
"metadata": {}
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "model.save_weights('/data/statefarm_weights.h5')",
"execution_count": 7,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "import pandas as pd\ncsv = pd.read_csv('/root/statefarm/sample_submission.csv')\npd.DataFrame(csv)",
"execution_count": 14,
"outputs": [
{
"output_type": "execute_result",
"execution_count": 14,
"data": {
"text/html": "<div>\n<style scoped>\n .dataframe tbody tr th:only-of-type {\n vertical-align: middle;\n }\n\n .dataframe tbody tr th {\n vertical-align: top;\n }\n\n .dataframe thead th {\n text-align: right;\n }\n</style>\n<table border=\"1\" class=\"dataframe\">\n <thead>\n <tr style=\"text-align: right;\">\n <th></th>\n <th>img</th>\n <th>c0</th>\n <th>c1</th>\n <th>c2</th>\n <th>c3</th>\n <th>c4</th>\n <th>c5</th>\n <th>c6</th>\n <th>c7</th>\n <th>c8</th>\n <th>c9</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>0</th>\n <td>img_1.jpg</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n </tr>\n <tr>\n <th>1</th>\n <td>img_10.jpg</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n </tr>\n <tr>\n <th>2</th>\n <td>img_100.jpg</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n </tr>\n <tr>\n <th>3</th>\n <td>img_1000.jpg</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n </tr>\n <tr>\n <th>4</th>\n <td>img_100000.jpg</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n </tr>\n <tr>\n <th>5</th>\n <td>img_100001.jpg</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n </tr>\n <tr>\n <th>6</th>\n <td>img_100002.jpg</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n </tr>\n <tr>\n <th>7</th>\n <td>img_100003.jpg</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n </tr>\n <tr>\n <th>8</th>\n <td>img_100004.jpg</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n </tr>\n <tr>\n <th>9</th>\n <td>img_100005.jpg</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n </tr>\n <tr>\n <th>10</th>\n <td>img_100007.jpg</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n </tr>\n <tr>\n <th>11</th>\n <td>img_100008.jpg</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n </tr>\n <tr>\n <th>12</th>\n <td>img_100009.jpg</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n </tr>\n <tr>\n <th>13</th>\n <td>img_10001.jpg</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n </tr>\n <tr>\n <th>14</th>\n <td>img_100010.jpg</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n </tr>\n <tr>\n <th>15</th>\n <td>img_100011.jpg</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n </tr>\n <tr>\n <th>16</th>\n <td>img_100012.jpg</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n </tr>\n <tr>\n <th>17</th>\n <td>img_100013.jpg</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n </tr>\n <tr>\n <th>18</th>\n <td>img_100014.jpg</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n </tr>\n <tr>\n <th>19</th>\n <td>img_100016.jpg</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n </tr>\n <tr>\n <th>20</th>\n <td>img_100017.jpg</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n </tr>\n <tr>\n <th>21</th>\n <td>img_100018.jpg</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n </tr>\n <tr>\n <th>22</th>\n <td>img_100019.jpg</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n </tr>\n <tr>\n <th>23</th>\n <td>img_10002.jpg</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n </tr>\n <tr>\n <th>24</th>\n <td>img_100020.jpg</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n </tr>\n <tr>\n <th>25</th>\n <td>img_100022.jpg</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n </tr>\n <tr>\n <th>26</th>\n <td>img_100023.jpg</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n </tr>\n <tr>\n <th>27</th>\n <td>img_100024.jpg</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n </tr>\n <tr>\n <th>28</th>\n <td>img_100025.jpg</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n </tr>\n <tr>\n <th>29</th>\n <td>img_100028.jpg</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n </tr>\n <tr>\n <th>...</th>\n <td>...</td>\n <td>...</td>\n <td>...</td>\n <td>...</td>\n <td>...</td>\n <td>...</td>\n <td>...</td>\n <td>...</td>\n <td>...</td>\n <td>...</td>\n <td>...</td>\n </tr>\n <tr>\n <th>79696</th>\n <td>img_99960.jpg</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n </tr>\n <tr>\n <th>79697</th>\n <td>img_99961.jpg</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n </tr>\n <tr>\n <th>79698</th>\n <td>img_99962.jpg</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n </tr>\n <tr>\n <th>79699</th>\n <td>img_99966.jpg</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n </tr>\n <tr>\n <th>79700</th>\n <td>img_99967.jpg</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n </tr>\n <tr>\n <th>79701</th>\n <td>img_99968.jpg</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n </tr>\n <tr>\n <th>79702</th>\n <td>img_99969.jpg</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n </tr>\n <tr>\n <th>79703</th>\n <td>img_9997.jpg</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n </tr>\n <tr>\n <th>79704</th>\n <td>img_99970.jpg</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n </tr>\n <tr>\n <th>79705</th>\n <td>img_99972.jpg</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n </tr>\n <tr>\n <th>79706</th>\n <td>img_99973.jpg</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n </tr>\n <tr>\n <th>79707</th>\n <td>img_99974.jpg</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n </tr>\n <tr>\n <th>79708</th>\n <td>img_99975.jpg</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n </tr>\n <tr>\n <th>79709</th>\n <td>img_99981.jpg</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n </tr>\n <tr>\n <th>79710</th>\n <td>img_99983.jpg</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n </tr>\n <tr>\n <th>79711</th>\n <td>img_99984.jpg</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n </tr>\n <tr>\n <th>79712</th>\n <td>img_99985.jpg</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n </tr>\n <tr>\n <th>79713</th>\n <td>img_99986.jpg</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n </tr>\n <tr>\n <th>79714</th>\n <td>img_99987.jpg</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n </tr>\n <tr>\n <th>79715</th>\n <td>img_99988.jpg</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n </tr>\n <tr>\n <th>79716</th>\n <td>img_99989.jpg</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n </tr>\n <tr>\n <th>79717</th>\n <td>img_9999.jpg</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n </tr>\n <tr>\n <th>79718</th>\n <td>img_99990.jpg</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n </tr>\n <tr>\n <th>79719</th>\n <td>img_99991.jpg</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n </tr>\n <tr>\n <th>79720</th>\n <td>img_99993.jpg</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n </tr>\n <tr>\n <th>79721</th>\n <td>img_99994.jpg</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n </tr>\n <tr>\n <th>79722</th>\n <td>img_99995.jpg</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n </tr>\n <tr>\n <th>79723</th>\n <td>img_99996.jpg</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n </tr>\n <tr>\n <th>79724</th>\n <td>img_99998.jpg</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n </tr>\n <tr>\n <th>79725</th>\n <td>img_99999.jpg</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n <td>0.1</td>\n </tr>\n </tbody>\n</table>\n<p>79726 rows × 11 columns</p>\n</div>",
"text/plain": " img c0 c1 c2 c3 c4 c5 c6 c7 c8 c9\n0 img_1.jpg 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1\n1 img_10.jpg 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1\n2 img_100.jpg 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1\n3 img_1000.jpg 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1\n4 img_100000.jpg 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1\n5 img_100001.jpg 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1\n6 img_100002.jpg 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1\n7 img_100003.jpg 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1\n8 img_100004.jpg 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1\n9 img_100005.jpg 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1\n10 img_100007.jpg 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1\n11 img_100008.jpg 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1\n12 img_100009.jpg 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1\n13 img_10001.jpg 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1\n14 img_100010.jpg 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1\n15 img_100011.jpg 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1\n16 img_100012.jpg 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1\n17 img_100013.jpg 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1\n18 img_100014.jpg 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1\n19 img_100016.jpg 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1\n20 img_100017.jpg 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1\n21 img_100018.jpg 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1\n22 img_100019.jpg 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1\n23 img_10002.jpg 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1\n24 img_100020.jpg 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1\n25 img_100022.jpg 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1\n26 img_100023.jpg 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1\n27 img_100024.jpg 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1\n28 img_100025.jpg 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1\n29 img_100028.jpg 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1\n... ... ... ... ... ... ... ... ... ... ... ...\n79696 img_99960.jpg 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1\n79697 img_99961.jpg 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1\n79698 img_99962.jpg 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1\n79699 img_99966.jpg 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1\n79700 img_99967.jpg 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1\n79701 img_99968.jpg 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1\n79702 img_99969.jpg 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1\n79703 img_9997.jpg 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1\n79704 img_99970.jpg 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1\n79705 img_99972.jpg 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1\n79706 img_99973.jpg 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1\n79707 img_99974.jpg 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1\n79708 img_99975.jpg 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1\n79709 img_99981.jpg 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1\n79710 img_99983.jpg 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1\n79711 img_99984.jpg 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1\n79712 img_99985.jpg 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1\n79713 img_99986.jpg 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1\n79714 img_99987.jpg 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1\n79715 img_99988.jpg 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1\n79716 img_99989.jpg 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1\n79717 img_9999.jpg 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1\n79718 img_99990.jpg 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1\n79719 img_99991.jpg 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1\n79720 img_99993.jpg 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1\n79721 img_99994.jpg 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1\n79722 img_99995.jpg 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1\n79723 img_99996.jpg 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1\n79724 img_99998.jpg 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1\n79725 img_99999.jpg 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1\n\n[79726 rows x 11 columns]"
},
"metadata": {}
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "import numpy as np\n\nall_test_images = image.list_pictures('/root/statefarm/test')\n\ndef predict(path):\n image_array = image.img_to_array(image.load_img(path, target_size=(224, 224)))\n return model.predict_on_batch(np.array([image_array]))\n\nresult = [predict(path) for path in all_test_images]",
"execution_count": 40,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "%ls /root/statefarm/",
"execution_count": 22,
"outputs": [
{
"output_type": "stream",
"text": "driver_imgs_list.csv sample_submission.csv \u001b[0m\u001b[01;34mtest\u001b[0m/ \u001b[01;34mtrain\u001b[0m/ \u001b[01;34mvalid\u001b[0m/\r\n",
"name": "stdout"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "predictions = np.concatenate(result)",
"execution_count": 41,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "np.savez_compressed('/root/statefarmprediction.npz', predictions=predictions)",
"execution_count": 43,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "!head /root/statefarm/sample_submission.csv",
"execution_count": 46,
"outputs": [
{
"output_type": "stream",
"text": "img,c0,c1,c2,c3,c4,c5,c6,c7,c8,c9\r\nimg_1.jpg,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1\r\nimg_10.jpg,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1\r\nimg_100.jpg,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1\r\nimg_1000.jpg,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1\r\nimg_100000.jpg,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1\r\nimg_100001.jpg,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1\r\nimg_100002.jpg,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1\r\nimg_100003.jpg,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1\r\nimg_100004.jpg,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1\r\n",
"name": "stdout"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "result1 = pd.DataFrame(predictions, columns=['c0', 'c1', 'c2', 'c3',\n 'c4', 'c5', 'c6', 'c7',\n 'c8', 'c9'])\nresult1.head()",
"execution_count": 64,
"outputs": [
{
"output_type": "execute_result",
"execution_count": 64,
"data": {
"text/html": "<div>\n<style scoped>\n .dataframe tbody tr th:only-of-type {\n vertical-align: middle;\n }\n\n .dataframe tbody tr th {\n vertical-align: top;\n }\n\n .dataframe thead th {\n text-align: right;\n }\n</style>\n<table border=\"1\" class=\"dataframe\">\n <thead>\n <tr style=\"text-align: right;\">\n <th></th>\n <th>c0</th>\n <th>c1</th>\n <th>c2</th>\n <th>c3</th>\n <th>c4</th>\n <th>c5</th>\n <th>c6</th>\n <th>c7</th>\n <th>c8</th>\n <th>c9</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>0</th>\n <td>1.384726e-06</td>\n <td>4.822928e-06</td>\n <td>9.999903e-01</td>\n <td>1.961031e-10</td>\n <td>1.339760e-06</td>\n <td>6.451069e-08</td>\n <td>6.184557e-08</td>\n <td>7.454797e-07</td>\n <td>1.169330e-06</td>\n <td>5.821764e-09</td>\n </tr>\n <tr>\n <th>1</th>\n <td>8.885561e-01</td>\n <td>1.234460e-05</td>\n <td>6.340341e-07</td>\n <td>1.398342e-03</td>\n <td>7.485374e-07</td>\n <td>3.079241e-06</td>\n <td>1.063647e-07</td>\n <td>6.492450e-09</td>\n <td>4.909646e-09</td>\n <td>1.100286e-01</td>\n </tr>\n <tr>\n <th>2</th>\n <td>1.683953e-07</td>\n <td>4.327632e-07</td>\n <td>3.031547e-07</td>\n <td>1.451190e-10</td>\n <td>1.490105e-10</td>\n <td>3.802628e-09</td>\n <td>2.149086e-09</td>\n <td>9.999943e-01</td>\n <td>3.419427e-06</td>\n <td>1.356876e-06</td>\n </tr>\n <tr>\n <th>3</th>\n <td>3.688046e-03</td>\n <td>9.844831e-01</td>\n <td>2.398118e-07</td>\n <td>5.908579e-05</td>\n <td>1.421544e-08</td>\n <td>1.041805e-06</td>\n <td>1.131379e-02</td>\n <td>1.272322e-05</td>\n <td>4.766718e-05</td>\n <td>3.942674e-04</td>\n </tr>\n <tr>\n <th>4</th>\n <td>1.633455e-07</td>\n <td>9.999108e-01</td>\n <td>7.788048e-05</td>\n <td>4.609768e-08</td>\n <td>1.126921e-09</td>\n <td>3.447050e-11</td>\n <td>5.138406e-06</td>\n <td>9.266722e-07</td>\n <td>4.955573e-06</td>\n <td>6.509162e-09</td>\n </tr>\n </tbody>\n</table>\n</div>",
"text/plain": " c0 c1 c2 c3 c4 \\\n0 1.384726e-06 4.822928e-06 9.999903e-01 1.961031e-10 1.339760e-06 \n1 8.885561e-01 1.234460e-05 6.340341e-07 1.398342e-03 7.485374e-07 \n2 1.683953e-07 4.327632e-07 3.031547e-07 1.451190e-10 1.490105e-10 \n3 3.688046e-03 9.844831e-01 2.398118e-07 5.908579e-05 1.421544e-08 \n4 1.633455e-07 9.999108e-01 7.788048e-05 4.609768e-08 1.126921e-09 \n\n c5 c6 c7 c8 c9 \n0 6.451069e-08 6.184557e-08 7.454797e-07 1.169330e-06 5.821764e-09 \n1 3.079241e-06 1.063647e-07 6.492450e-09 4.909646e-09 1.100286e-01 \n2 3.802628e-09 2.149086e-09 9.999943e-01 3.419427e-06 1.356876e-06 \n3 1.041805e-06 1.131379e-02 1.272322e-05 4.766718e-05 3.942674e-04 \n4 3.447050e-11 5.138406e-06 9.266722e-07 4.955573e-06 6.509162e-09 "
},
"metadata": {}
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "from os import path\ntest_id = [path.basename(p) for p in image.list_pictures('/root/statefarm/test')]\nresult1.insert(loc=0, column='img', value=test_id)",
"execution_count": 65,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "result1.head()",
"execution_count": 66,
"outputs": [
{
"output_type": "execute_result",
"execution_count": 66,
"data": {
"text/html": "<div>\n<style scoped>\n .dataframe tbody tr th:only-of-type {\n vertical-align: middle;\n }\n\n .dataframe tbody tr th {\n vertical-align: top;\n }\n\n .dataframe thead th {\n text-align: right;\n }\n</style>\n<table border=\"1\" class=\"dataframe\">\n <thead>\n <tr style=\"text-align: right;\">\n <th></th>\n <th>img</th>\n <th>c0</th>\n <th>c1</th>\n <th>c2</th>\n <th>c3</th>\n <th>c4</th>\n <th>c5</th>\n <th>c6</th>\n <th>c7</th>\n <th>c8</th>\n <th>c9</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>0</th>\n <td>img_34547.jpg</td>\n <td>1.384726e-06</td>\n <td>4.822928e-06</td>\n <td>9.999903e-01</td>\n <td>1.961031e-10</td>\n <td>1.339760e-06</td>\n <td>6.451069e-08</td>\n <td>6.184557e-08</td>\n <td>7.454797e-07</td>\n <td>1.169330e-06</td>\n <td>5.821764e-09</td>\n </tr>\n <tr>\n <th>1</th>\n <td>img_53510.jpg</td>\n <td>8.885561e-01</td>\n <td>1.234460e-05</td>\n <td>6.340341e-07</td>\n <td>1.398342e-03</td>\n <td>7.485374e-07</td>\n <td>3.079241e-06</td>\n <td>1.063647e-07</td>\n <td>6.492450e-09</td>\n <td>4.909646e-09</td>\n <td>1.100286e-01</td>\n </tr>\n <tr>\n <th>2</th>\n <td>img_94820.jpg</td>\n <td>1.683953e-07</td>\n <td>4.327632e-07</td>\n <td>3.031547e-07</td>\n <td>1.451190e-10</td>\n <td>1.490105e-10</td>\n <td>3.802628e-09</td>\n <td>2.149086e-09</td>\n <td>9.999943e-01</td>\n <td>3.419427e-06</td>\n <td>1.356876e-06</td>\n </tr>\n <tr>\n <th>3</th>\n <td>img_35927.jpg</td>\n <td>3.688046e-03</td>\n <td>9.844831e-01</td>\n <td>2.398118e-07</td>\n <td>5.908579e-05</td>\n <td>1.421544e-08</td>\n <td>1.041805e-06</td>\n <td>1.131379e-02</td>\n <td>1.272322e-05</td>\n <td>4.766718e-05</td>\n <td>3.942674e-04</td>\n </tr>\n <tr>\n <th>4</th>\n <td>img_44296.jpg</td>\n <td>1.633455e-07</td>\n <td>9.999108e-01</td>\n <td>7.788048e-05</td>\n <td>4.609768e-08</td>\n <td>1.126921e-09</td>\n <td>3.447050e-11</td>\n <td>5.138406e-06</td>\n <td>9.266722e-07</td>\n <td>4.955573e-06</td>\n <td>6.509162e-09</td>\n </tr>\n </tbody>\n</table>\n</div>",
"text/plain": " img c0 c1 c2 c3 \\\n0 img_34547.jpg 1.384726e-06 4.822928e-06 9.999903e-01 1.961031e-10 \n1 img_53510.jpg 8.885561e-01 1.234460e-05 6.340341e-07 1.398342e-03 \n2 img_94820.jpg 1.683953e-07 4.327632e-07 3.031547e-07 1.451190e-10 \n3 img_35927.jpg 3.688046e-03 9.844831e-01 2.398118e-07 5.908579e-05 \n4 img_44296.jpg 1.633455e-07 9.999108e-01 7.788048e-05 4.609768e-08 \n\n c4 c5 c6 c7 c8 \\\n0 1.339760e-06 6.451069e-08 6.184557e-08 7.454797e-07 1.169330e-06 \n1 7.485374e-07 3.079241e-06 1.063647e-07 6.492450e-09 4.909646e-09 \n2 1.490105e-10 3.802628e-09 2.149086e-09 9.999943e-01 3.419427e-06 \n3 1.421544e-08 1.041805e-06 1.131379e-02 1.272322e-05 4.766718e-05 \n4 1.126921e-09 3.447050e-11 5.138406e-06 9.266722e-07 4.955573e-06 \n\n c9 \n0 5.821764e-09 \n1 1.100286e-01 \n2 1.356876e-06 \n3 3.942674e-04 \n4 6.509162e-09 "
},
"metadata": {}
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "result1.to_csv('statefarm_submission.csv', index=False)",
"execution_count": 85,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "!head ./statefarm_submission.csv",
"execution_count": 86,
"outputs": [
{
"output_type": "stream",
"text": "img,c0,c1,c2,c3,c4,c5,c6,c7,c8,c9\r\nimg_34547.jpg,1.3847256923327222e-06,4.822927621717099e-06,0.9999903440475464,1.9610305046491305e-10,1.339760160590231e-06,6.45106936758566e-08,6.184556866628554e-08,7.454797241734923e-07,1.169329948425002e-06,5.821764403890484e-09\r\nimg_53510.jpg,0.8885561227798462,1.2344598872005008e-05,6.340341087707202e-07,0.0013983421958982944,7.485374453608529e-07,3.0792409688729094e-06,1.0636473035674499e-07,6.492449688977331e-09,4.909646023065761e-09,0.11002857983112335\r\nimg_94820.jpg,1.683953172459951e-07,4.3276318706375605e-07,3.031546782494843e-07,1.4511895851665457e-10,1.4901047062920725e-10,3.8026284343573025e-09,2.1490857982087164e-09,0.9999942779541016,3.4194267755083274e-06,1.3568762824434089e-06\r\nimg_35927.jpg,0.0036880457773804665,0.9844830632209778,2.398118112978409e-07,5.90857925999444e-05,1.4215435051312397e-08,1.0418053761895862e-06,0.011313789524137974,1.2723223335342482e-05,4.766718120663427e-05,0.00039426740841008723\r\nimg_44296.jpg,1.6334553265551222e-07,0.999910831451416,7.788047514623031e-05,4.609767501051465e-08,1.1269212230047287e-09,3.447050284099973e-11,5.138405867910478e-06,9.26672157675057e-07,4.955572876497172e-06,6.5091616541224084e-09\r\nimg_48602.jpg,7.2112561610993e-07,4.2530973187737686e-10,5.892658805350948e-09,2.96985408487771e-10,3.935753389860963e-10,0.9999654293060303,2.26197407471318e-08,6.246213615668239e-06,2.3907401555334218e-05,3.6205651667842176e-06\r\nimg_54737.jpg,0.00012325476564001292,7.252812065416947e-05,0.00032328139059245586,4.1385024815099314e-05,0.9942856431007385,4.760510208257074e-08,0.0005391726735979319,3.473932156339288e-05,0.00457970192655921,3.465900419996615e-07\r\nimg_80713.jpg,0.20046068727970123,0.26589399576187134,0.195068821310997,0.12235323339700699,0.023642994463443756,0.041352786123752594,0.10411690920591354,0.0005659174057655036,0.0004464928642846644,0.046098172664642334\r\nimg_17786.jpg,0.9999953508377075,1.3178728295315523e-06,5.053223972595333e-08,2.3118637670904718e-07,4.254046004348311e-09,2.2510666894959286e-06,7.407734869957494e-07,2.875235119437214e-11,4.564247202409888e-09,8.452104793832405e-08\r\n",
"name": "stdout"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "!kg submit statefarm_submission.csv -c state-farm-distracted-driver-detection",
"execution_count": 87,
"outputs": [
{
"output_type": "stream",
"text": "0.83847\r\n",
"name": "stdout"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "%cp /data/statefarm_submission.csv .\nfrom IPython.display import FileLink\nFileLink('statefarm_submission.csv')",
"execution_count": 82,
"outputs": [
{
"output_type": "execute_result",
"execution_count": 82,
"data": {
"text/html": "<a href='statefarm_submission.csv' target='_blank'>statefarm_submission.csv</a><br>",
"text/plain": "/notebooks/Learning/Lesson1/statefarm_submission.csv"
},
"metadata": {}
}
]
}
],
"metadata": {
"notify_time": "5",
"kernelspec": {
"name": "python3",
"display_name": "Python 3",
"language": "python"
},
"language_info": {
"name": "python",
"pygments_lexer": "ipython3",
"version": "3.5.2",
"nbconvert_exporter": "python",
"codemirror_mode": {
"version": 3,
"name": "ipython"
},
"file_extension": ".py",
"mimetype": "text/x-python"
},
"gist": {
"id": "",
"data": {
"description": "Learning/Lesson1/StateFarm.ipynb",
"public": true
}
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment