Skip to content

Commit

Permalink
ImgToMap finished
Browse files Browse the repository at this point in the history
  • Loading branch information
arshit09 committed Sep 28, 2019
1 parent 8f1f300 commit 478a46f
Show file tree
Hide file tree
Showing 3 changed files with 131 additions and 17 deletions.
2 changes: 1 addition & 1 deletion frontend/js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ $('document').ready(function(){
}
reader.readAsDataURL($('#input_handle')[0].files[0]);

$('#output_image').attr("src", 'http://127.0.0.1:5000/static/uploads/' + data);
$('#output_image').attr("src", 'http://127.0.0.1:5000/static/outputs/' + data);
}
});
});
Expand Down
108 changes: 108 additions & 0 deletions server/codes/blurtohd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# example of loading a pix2pix model and using it for image to image translation
from keras.models import load_model
from numpy import load
from numpy import vstack
from matplotlib import pyplot
from numpy.random import randint

# load and prepare training images
def load_real_samples(filename):
# load compressed arrays
data = load(filename)
# unpack arrays
X1, X2 = data['arr_0'], data['arr_1']
# scale from [0,255] to [-1,1]
X1 = (X1 - 127.5) / 127.5
X2 = (X2 - 127.5) / 127.5
return [X1, X2]

# plot source, generated and target images
def plot_images(src_img, gen_img, tar_img):
images = vstack((src_img, gen_img, tar_img))
# scale from [-1,1] to [0,1]
images = (images + 1) / 2.0
titles = ['Source', 'Generated', 'Expected']
# plot images row by row
for i in range(len(images)):
# define subplot
pyplot.subplot(1, 3, 1 + i)
# turn off axis
pyplot.axis('off')
# plot raw pixel data
pyplot.imshow(images[i])
# show title
pyplot.title(titles[i])
pyplot.show()

# load dataset
[X1, X2] = load_real_samples('maps_256.npz')
print('Loaded', X1.shape, X2.shape)
# load model
model = load_model('g_model.h5')
# select random example
ix = randint(0, len(X1), 1)
print(ix)
src_image, tar_image = X1[ix], X2[ix]
# generate image from source
gen_image = model.predict(src_image)
# plot all three images
plot_images(src_image, gen_image, tar_image)
print(type(src_image), gen_image.shape, tar_image.shape)


##########################################################

import os
from keras.preprocessing.image import img_to_array
from keras.preprocessing.image import load_img
from keras.models import load_model
from matplotlib import pyplot as plt
import numpy as np
from numpy import vstack
import time


model = load_model('g_model.h5')

##############################################################

filename="./Capture1.PNG"
size=(256,256)
pixels = load_img(filename, target_size=size)

# convert to numpy array
pixels = img_to_array(pixels)
# split into satellite and map
sat_img = pixels[:, :256]
sat_img = (sat_img - 127.5) / 127.5


input_image=[]
input_image.append(sat_img)
input_image=np.array(input_image)

t1=time.time()
gen_image=model.predict(input_image)
t2=time.time()

###########################################################

from matplotlib import pyplot
def show_images(src_img, gen_img):
images = vstack((src_img, gen_img))
# scale from [-1,1] to [0,1]
images = (images + 1) / 2.0
titles = ['Source', 'Generated']
# plot images row by row
for i in range(len(images)):
# define subplot
pyplot.subplot(1, 2, 1 + i)
# turn off axis
pyplot.axis('off')
# plot raw pixel data
pyplot.imshow(images[i])
# show title
pyplot.title(titles[i])
pyplot.show()

show_images(input_image,gen_image)
38 changes: 22 additions & 16 deletions server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,20 @@
import os
import random
import numpy as np
import time

#image_to_map
from keras.preprocessing.image import img_to_array
from keras.preprocessing.image import load_img
from matplotlib import pyplot as plt
from numpy import vstack

image_to_map = load_model('models/image_to_map_g_model.h5')
image_to_map._make_predict_function()

global graph
graph = tf.get_default_graph()

image_to_map = load_model('models/image_to_map.h5')

app = Flask(__name__)
CORS(app)
app.config['UPLOAD_FOLDER'] = 'static/uploads'
Expand All @@ -27,25 +34,24 @@ def predict(filename, process_type):
if process_type == 'fogg_removal':
pass
if process_type == 'image_to_map':
# size=(256,256)
# sat_img = load_img(input_path, target_size=size)
# sat_img = img_to_array(sat_img)
# # split into satellite and map
# sat_img = (sat_img - 127.5) / 127.5

# input_image=[]
# input_image.append(sat_img)
# input_image=np.array(input_image)
# gen_image=image_to_map.predict(input_image)
# gen_image=(gen_image+1)/2.0
# save_img(output_path, gen_image)
pass
size=(256,256)
#image_to_map = load_model('models/image_to_map_g_model.h5')
sat_img = load_img(input_path, target_size=size)
sat_img = img_to_array(sat_img)
# split into satellite and map
sat_img = (sat_img - 127.5) / 127.5
input_image=[]
input_image.append(sat_img)
input_image=np.array(input_image)
print(input_image.shape)
gen_image=image_to_map.predict(input_image)
gen_image=(gen_image+1)/2.0
save_img(output_path, gen_image[0])
if process_type == 'blur_to_hd':
pass
if process_type == 'face_aging':
pass


@app.route("/")
def index():
return "helllo"
Expand Down

0 comments on commit 478a46f

Please sign in to comment.