Skip to content

Commit

Permalink
urban - rural image classifier
Browse files Browse the repository at this point in the history
  • Loading branch information
srikantvadrevu committed Jan 7, 2019
1 parent e3c1c40 commit 79849ae
Show file tree
Hide file tree
Showing 191 changed files with 133 additions and 0 deletions.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/rural_and_urban_photos/__MACOSX/val/._.DS_Store
Binary file not shown.
Binary file added data/rural_and_urban_photos/train/.DS_Store
Binary file not shown.
Binary file not shown.
Binary file added data/rural_and_urban_photos/val/.DS_Store
Binary file not shown.
Binary file added data/rural_and_urban_photos/val/rural/rural0.jpeg
Binary file added data/rural_and_urban_photos/val/rural/rural5.jpeg
Binary file added data/rural_and_urban_photos/val/urban/urban0.jpeg
133 changes: 133 additions & 0 deletions urban-rural-classification.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# kaggle challenge - https://www.kaggle.com/dansbecker/urban-and-rural-photos/home\n",
"from tensorflow.python.keras.applications import ResNet50\n",
"from tensorflow.python.keras.models import Sequential\n",
"from tensorflow.python.keras.layers import Dense, Flatten, GlobalAveragePooling2D, Dropout\n",
"\n",
"num_classes = 2"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"model = Sequential()\n",
"model.add(ResNet50(include_top=False, pooling='avg'))\n",
"model.add(Dropout(0.25))\n",
"model.add(Dense(128, activation='relu'))\n",
"model.add(Dense(num_classes, activation='softmax'))\n",
"\n",
"model.layers[0].trainable = False"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"model.compile(optimizer='sgd', loss='categorical_crossentropy', metrics=['accuracy'])"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Found 72 images belonging to 2 classes.\n",
"Found 20 images belonging to 2 classes.\n",
"Epoch 1/3\n",
"3/3 [==============================] - 22s 7s/step - loss: 0.6569 - acc: 0.6389 - val_loss: 0.5272 - val_acc: 0.7500\n",
"Epoch 2/3\n",
"3/3 [==============================] - 20s 7s/step - loss: 0.3589 - acc: 0.8750 - val_loss: 0.3867 - val_acc: 0.9500\n",
"Epoch 3/3\n",
"3/3 [==============================] - 20s 7s/step - loss: 0.2804 - acc: 0.9444 - val_loss: 0.2924 - val_acc: 0.9500\n"
]
},
{
"data": {
"text/plain": [
"<tensorflow.python.keras.callbacks.History at 0x1a198127588>"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from tensorflow.python.keras.applications.resnet50 import preprocess_input\n",
"from tensorflow.python.keras.preprocessing.image import ImageDataGenerator\n",
"\n",
"image_size = 224\n",
"data_generator = ImageDataGenerator(\n",
" preprocessing_function=preprocess_input,\n",
" horizontal_flip=True,\n",
" width_shift_range = 0.2,\n",
" height_shift_range = 0.2\n",
")\n",
"\n",
"train_generator = data_generator.flow_from_directory(\n",
" 'data/rural_and_urban_photos/train',\n",
" target_size=(image_size, image_size),\n",
" batch_size=24,\n",
" class_mode='categorical'\n",
")\n",
"\n",
"validation_generator = data_generator.flow_from_directory(\n",
" 'data/rural_and_urban_photos/val',\n",
" target_size=(image_size, image_size),\n",
" class_mode='categorical'\n",
")\n",
"\n",
"model.fit_generator(\n",
" train_generator,\n",
" steps_per_epoch=3,\n",
" validation_data=validation_generator,\n",
" validation_steps=1,\n",
" epochs=3\n",
")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python [conda env:nnseries]",
"language": "python",
"name": "conda-env-nnseries-py"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

0 comments on commit 79849ae

Please sign in to comment.