-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsat2map.py
34 lines (30 loc) · 1011 Bytes
/
sat2map.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# example of loading a pix2pix model and using it for one-off image translation
from keras.models import load_model
from keras.preprocessing.image import img_to_array
from keras.preprocessing.image import load_img
from numpy import expand_dims
from matplotlib import pyplot
# load an image
def load_image(filename, size=(256, 256)):
# load image with the preferred size
pixels = load_img(filename, target_size=size)
# convert to numpy array
pixels = img_to_array(pixels)
# scale from [0,255] to [-1,1]
pixels = (pixels - 127.5) / 127.5
# reshape to 1 sample
pixels = expand_dims(pixels, 0)
return pixels
# load source image
src_image = load_image('./data/satellite.jpg')
print('Loaded', src_image.shape)
# load model
model = load_model('./models/model_109600.h5')
# generate image from source
gen_image = model.predict(src_image)
# scale from [-1,1] to [0,1]
gen_image = (gen_image + 1) / 2.0
# plot the image
pyplot.imshow(gen_image[0])
pyplot.axis('off')
pyplot.show()