added examples

This commit is contained in:
BKHMSI 2017-06-01 17:46:09 +02:00
parent a0b50f16d3
commit 9d52061d8b
18 changed files with 1219 additions and 225 deletions

BIN
Examples/building_7.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

BIN
Examples/building_8.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB

BIN
Examples/building_9.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 56 KiB

BIN
Examples/coliseum.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 88 KiB

BIN
Examples/faces_1.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

BIN
Examples/faces_2.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 69 KiB

BIN
Examples/faces_3.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 65 KiB

BIN
Examples/faces_4.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

BIN
Examples/faces_5.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 65 KiB

BIN
Examples/faces_6.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

BIN
Examples/feature_loss.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

BIN
Examples/pixel_loss.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB

BIN
Examples/totalv_loss.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

View File

@ -3,17 +3,20 @@ import numpy as np
import os
from filters import PencilSketch
m = 240
n = 320
DIR_PATH = 'ZuBuD'
SKETCH_PATH = 'ZuBuD_Sketch'
for file in os.listdir('ZuBuD'):
file_path = os.path.join('ZuBuD', file)
for file in os.listdir(DIR_PATH):
file_path = os.path.join(DIR_PATH, file)
img = cv.imread(file_path)
img = cv.cvtColor(img, cv.COLOR_BGR2RGB)
print (img.shape)
height, width, channels = img.shape
if (height, width, channels) == (240,320,3):
img = np.resize(img, (480, 640, 3))
if (height, width, channels) != (m, n, 3):
img = np.resize(img, (m, n, 3))
pencil = PencilSketch(width, height)
sketch = pencil.render(img)
write_path = os.path.join('ZuBuD_Sketch', file)
write_path = os.path.join(SKETCH_PATH, file)
cv.imwrite(write_path, sketch)

View File

@ -1,219 +0,0 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import os\n",
"import numpy as np\n",
"import pandas as pd \n",
"import cv2 as cv\n",
"import scipy.misc\n",
"\n",
"from sklearn.preprocessing import StandardScaler\n",
"from keras.models import Sequential, Model\n",
"from keras.layers import Input, Dense, Conv2D, MaxPooling2D, UpSampling2D\n",
"from keras.layers.core import Activation, Dropout, Flatten\n",
"from keras.optimizers import SGD\n",
"from keras.utils import np_utils\n",
"from keras.callbacks import TensorBoard\n",
"\n",
"np.random.seed(1337) # for reproducibility"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"((1005, 480, 640, 3), (1005, 480, 640, 3))\n"
]
}
],
"source": [
"num_images = (1005, 480, 640, 3)\n",
"X_train = np.zeros(num_images)\n",
"Y_train = np.zeros(num_images)\n",
"\n",
"for i, file in enumerate(os.listdir('ZuBuD_Sketch')):\n",
" file_path = os.path.join('ZuBuD_Sketch', file)\n",
" img = cv.imread(file_path)\n",
" img = cv.cvtColor(img, cv.COLOR_BGR2RGB)\n",
" X_train[i] = img\n",
" \n",
"for i, file in enumerate(os.listdir('ZuBuD')):\n",
" file_path = os.path.join('ZuBuD', file)\n",
" img = cv.imread(file_path)\n",
" img = cv.cvtColor(img, cv.COLOR_BGR2RGB) \n",
" if img.shape == (240,320,3):\n",
" img = scipy.misc.imresize(img, (480, 640, 3))\n",
" Y_train[i] = img\n",
" \n",
"print (X_train.shape, Y_train.shape) "
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"X_val = X_train[:100]\n",
"Y_val = Y_train[:100]\n",
"X_train = X_train[100:]\n",
"Y_train = Y_train[100:]"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"_________________________________________________________________\n",
"Layer (type) Output Shape Param # \n",
"=================================================================\n",
"input_4 (InputLayer) (None, 480, 640, 3) 0 \n",
"_________________________________________________________________\n",
"conv2d_22 (Conv2D) (None, 480, 640, 128) 3584 \n",
"_________________________________________________________________\n",
"max_pooling2d_10 (MaxPooling (None, 240, 320, 128) 0 \n",
"_________________________________________________________________\n",
"conv2d_23 (Conv2D) (None, 240, 320, 64) 73792 \n",
"_________________________________________________________________\n",
"max_pooling2d_11 (MaxPooling (None, 120, 160, 64) 0 \n",
"_________________________________________________________________\n",
"conv2d_24 (Conv2D) (None, 120, 160, 64) 36928 \n",
"_________________________________________________________________\n",
"max_pooling2d_12 (MaxPooling (None, 60, 80, 64) 0 \n",
"_________________________________________________________________\n",
"conv2d_25 (Conv2D) (None, 60, 80, 64) 36928 \n",
"_________________________________________________________________\n",
"up_sampling2d_10 (UpSampling (None, 120, 160, 64) 0 \n",
"_________________________________________________________________\n",
"conv2d_26 (Conv2D) (None, 120, 160, 64) 36928 \n",
"_________________________________________________________________\n",
"up_sampling2d_11 (UpSampling (None, 240, 320, 64) 0 \n",
"_________________________________________________________________\n",
"conv2d_27 (Conv2D) (None, 240, 320, 128) 73856 \n",
"_________________________________________________________________\n",
"up_sampling2d_12 (UpSampling (None, 480, 640, 128) 0 \n",
"_________________________________________________________________\n",
"conv2d_28 (Conv2D) (None, 480, 640, 3) 3459 \n",
"=================================================================\n",
"Total params: 265,475.0\n",
"Trainable params: 265,475.0\n",
"Non-trainable params: 0.0\n",
"_________________________________________________________________\n"
]
}
],
"source": [
"input_img = Input(shape=(480, 640, 3)) \n",
"\n",
"x = Conv2D(128, (3, 3), activation='relu', padding='same')(input_img)\n",
"x = MaxPooling2D((2, 2), padding='same')(x)\n",
"x = Conv2D(64, (3, 3), activation='relu', padding='same')(x)\n",
"x = MaxPooling2D((2, 2), padding='same')(x)\n",
"x = Conv2D(64, (3, 3), activation='relu', padding='same')(x)\n",
"encoded = MaxPooling2D((2, 2), padding='same')(x)\n",
"\n",
"# at this point the representation is (4, 4, 8) i.e. 128-dimensional\n",
"\n",
"x = Conv2D(64, (3, 3), activation='relu', padding='same')(encoded)\n",
"x = UpSampling2D((2, 2))(x)\n",
"x = Conv2D(64, (3, 3), activation='relu', padding='same')(x)\n",
"x = UpSampling2D((2, 2))(x)\n",
"x = Conv2D(128, (3, 3), activation='relu', padding='same')(x)\n",
"x = UpSampling2D((2, 2))(x)\n",
"decoded = Conv2D(3, (3, 3), activation='sigmoid', padding='same')(x)\n",
"\n",
"autoencoder = Model(input_img, decoded)\n",
"autoencoder.summary()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Train on 905 samples, validate on 100 samples\n",
"Epoch 1/50\n"
]
}
],
"source": [
"autoencoder.compile(optimizer='adam', loss='mean_squared_error')\n",
"autoencoder.fit(X_train, Y_train,\n",
" epochs=12,\n",
" batch_size=64,\n",
" shuffle=True,\n",
" validation_data=(X_val, Y_val))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"Y_test = autoencoder.predict(X_val)\n",
"\n",
"fig = plt.figure()\n",
"a = fig.add_subplot(1,2,1)\n",
"imgplot = plt.imshow(Y_test[0])\n",
"a.set_title('Prediction')\n",
"a = fig.add_subplot(1,2,2)\n",
"imgplot = plt.imshow(X_val[0])\n",
"a.set_title('Ground Truth')\n",
"plt.show()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.13"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

BIN
poster.pdf Normal file

Binary file not shown.

1210
sketchback.ipynb Executable file

File diff suppressed because one or more lines are too long