MCPcopy Index your code
hub / github.com/tensorpack/tensorpack / Model

Class Model

examples/basics/export-model.py:40–73  ·  view source on GitHub ↗

Just a simple model, which applies the Laplacian-operation to images to showcase the usage of variables, and alternating the inference-graph later.

Source from the content-addressed store, hash-verified

38
39
40class Model(ModelDesc):
41 """Just a simple model, which applies the Laplacian-operation to images to showcase
42 the usage of variables, and alternating the inference-graph later.
43 """
44
45 def inputs(self):
46 return [tf.TensorSpec((None, SHAPE, SHAPE, CHANNELS), tf.uint8, 'input_img'),
47 tf.TensorSpec((None, SHAPE, SHAPE, CHANNELS), tf.uint8, 'target_img')]
48
49 def make_prediction(self, img):
50
51 img = tf.cast(img, tf.float32)
52 img = tf.image.rgb_to_grayscale(img)
53
54 k = tf.get_variable('filter', dtype=tf.float32,
55 initializer=[[[[0.]], [[1.]], [[0.]]], [
56 [[1.]], [[-4.]], [[1.]]], [[[0.]], [[1.]], [[0.]]]])
57 prediction_img = tf.nn.conv2d(img, k, strides=[1, 1, 1, 1], padding='SAME')
58 return prediction_img
59
60 def build_graph(self, input_img, target_img):
61
62 target_img = tf.cast(target_img, tf.float32)
63 target_img = tf.image.rgb_to_grayscale(target_img)
64
65 self.prediction_img = tf.identity(self.make_prediction(input_img), name='prediction_img')
66
67 cost = tf.losses.mean_squared_error(target_img, self.prediction_img,
68 reduction=tf.losses.Reduction.MEAN)
69 return tf.identity(cost, name='total_costs')
70
71 def optimizer(self):
72 lr = tf.get_variable('learning_rate', initializer=0.0, trainable=False)
73 return tf.train.AdamOptimizer(lr)
74
75
76def get_data(subset):

Callers 3

export_compactFunction · 0.70
applyFunction · 0.70
export-model.pyFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected