This repository has been archived by the owner on Aug 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdsrcnn.py
58 lines (45 loc) · 2.14 KB
/
dsrcnn.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import keras
print keras.__version__
import sys
from keras.layers import Conv2D, Input, BatchNormalization, UpSampling2D, Deconvolution2D, Conv2DTranspose, Activation, add
from keras.callbacks import ModelCheckpoint, Callback, TensorBoard
from keras.optimizers import SGD, Adam
from keras.models import Model
import numpy
import coremltools
print keras.__version__
def model():
inputLayer = Input(shape=(256, 256, 3))
DSRCNN = UpSampling2D(size=2)(inputLayer)
inputImage = DSRCNN
DSRCNN = Conv2D(9, (3, 3), strides=(1, 1), padding="same", init='glorot_uniform')(DSRCNN)
DSRCNN = Activation("relu")(DSRCNN)
DSRCNN = Conv2D(16, (3, 3), strides=(1, 1), padding="same", init='glorot_uniform')(DSRCNN)
DSRCNN = Activation("relu")(DSRCNN)
DSRCNN = Conv2D(32, (3, 3), strides=(1, 1), padding="same", init='glorot_uniform')(DSRCNN)
DSRCNN = Activation("relu")(DSRCNN)
DSRCNN = Conv2D(64, (3, 3), strides=(1, 1), padding="same", init='glorot_uniform')(DSRCNN)
DSRCNN = Activation("relu")(DSRCNN)
DSRCNN = Conv2D(64, (3, 3), strides=(1, 1), padding="same", init='glorot_uniform')(DSRCNN)
DSRCNN = Activation("relu")(DSRCNN)
DSRCNN = Conv2D(64, (3, 3), strides=(1, 1), padding="same", init='glorot_uniform')(DSRCNN)
DSRCNN = Activation("relu")(DSRCNN)
DSRCNN = Conv2D(32, (3, 3), strides=(1, 1), padding="same", init='glorot_uniform')(DSRCNN)
DSRCNN = Activation("relu")(DSRCNN)
DSRCNN = Conv2D(16, (3, 3), strides=(1, 1), padding="same", init='glorot_uniform')(DSRCNN)
DSRCNN = Activation("relu")(DSRCNN)
DSRCNN = Conv2D(9, (3, 3), strides=(1, 1), padding="same", init='glorot_uniform')(DSRCNN)
DSRCNN = Activation("relu")(DSRCNN)
DSRCNN = Conv2D(3, (3, 3), strides=(1, 1), padding="same", init='glorot_uniform')(DSRCNN)
DSRCNN = Activation("linear")(DSRCNN)
residualImage = DSRCNN
outputImage = add([inputImage, residualImage])
DSRCNN = Model(inputLayer, outputImage)
print DSRCNN.summary()
return DSRCNN
def save_model(model, name):
coreml_model = coremltools.converters.keras.convert(model,
input_names = 'image',
image_input_names = 'image',
image_scale = 0.00392156863)
coreml_model.save("./" + name + ".mlmodel")