| 27 | |
| 28 | |
| 29 | class Model(GANModelDesc): |
| 30 | def inputs(self): |
| 31 | return [tf.TensorSpec((None, args.final_size, args.final_size, 3), tf.float32, 'input')] |
| 32 | |
| 33 | @auto_reuse_variable_scope |
| 34 | def decoder(self, z): |
| 35 | l = FullyConnected('fc', z, NF * 8 * 8) |
| 36 | l = tf.reshape(l, [-1, 8, 8, NF]) |
| 37 | |
| 38 | with argscope(Conv2D, activation=tf.nn.elu, kernel_size=3, strides=1): |
| 39 | l = (LinearWrap(l) |
| 40 | .Conv2D('conv1.1', NF) |
| 41 | .Conv2D('conv1.2', NF) |
| 42 | .tf.image.resize_nearest_neighbor([16, 16], align_corners=True) |
| 43 | .Conv2D('conv2.1', NF) |
| 44 | .Conv2D('conv2.2', NF) |
| 45 | .tf.image.resize_nearest_neighbor([32, 32], align_corners=True) |
| 46 | .Conv2D('conv3.1', NF) |
| 47 | .Conv2D('conv3.2', NF) |
| 48 | .tf.image.resize_nearest_neighbor([64, 64], align_corners=True) |
| 49 | .Conv2D('conv4.1', NF) |
| 50 | .Conv2D('conv4.2', NF) |
| 51 | .Conv2D('conv4.3', 3, activation=tf.identity)()) |
| 52 | return l |
| 53 | |
| 54 | @auto_reuse_variable_scope |
| 55 | def encoder(self, imgs): |
| 56 | with argscope(Conv2D, activation=tf.nn.elu, kernel_size=3, strides=1): |
| 57 | l = (LinearWrap(imgs) |
| 58 | .Conv2D('conv1.1', NF) |
| 59 | .Conv2D('conv1.2', NF) |
| 60 | .Conv2D('conv1.3', NF * 2) |
| 61 | .AvgPooling('pool1', 2) |
| 62 | # 32 |
| 63 | .Conv2D('conv2.1', NF * 2) |
| 64 | .Conv2D('conv2.2', NF * 3) |
| 65 | .AvgPooling('pool2', 2) |
| 66 | # 16 |
| 67 | .Conv2D('conv3.1', NF * 3) |
| 68 | .Conv2D('conv3.2', NF * 4) |
| 69 | .AvgPooling('pool3', 2) |
| 70 | # 8 |
| 71 | .Conv2D('conv4.1', NF * 4) |
| 72 | .Conv2D('conv4.2', NF * 4) |
| 73 | |
| 74 | .FullyConnected('fc', NH)()) |
| 75 | return l |
| 76 | |
| 77 | def build_graph(self, image_pos): |
| 78 | image_pos = image_pos / 128.0 - 1 |
| 79 | |
| 80 | z = tf.random_uniform([args.batch, args.z_dim], minval=-1, maxval=1, name='z_train') |
| 81 | z = tf.placeholder_with_default(z, [None, args.z_dim], name='z') |
| 82 | |
| 83 | def summary_image(name, x): |
| 84 | x = (x + 1.0) * 128.0 |
| 85 | x = tf.clip_by_value(x, 0, 255) |
| 86 | tf.summary.image(name, tf.cast(x, tf.uint8), max_outputs=30) |
no outgoing calls
no test coverage detected
searching dependent graphs…