(self, image, label)
| 26 | tf.TensorSpec([None], tf.int32, 'label')] |
| 27 | |
| 28 | def build_graph(self, image, label): |
| 29 | image = image / 128.0 |
| 30 | |
| 31 | def inception(name, x, nr1x1, nr3x3r, nr3x3, nr233r, nr233, nrpool, pooltype): |
| 32 | stride = 2 if nr1x1 == 0 else 1 |
| 33 | with tf.variable_scope(name): |
| 34 | outs = [] |
| 35 | if nr1x1 != 0: |
| 36 | outs.append(Conv2D('conv1x1', x, nr1x1, 1)) |
| 37 | x2 = Conv2D('conv3x3r', x, nr3x3r, 1) |
| 38 | outs.append(Conv2D('conv3x3', x2, nr3x3, 3, strides=stride)) |
| 39 | |
| 40 | x3 = Conv2D('conv233r', x, nr233r, 1) |
| 41 | x3 = Conv2D('conv233a', x3, nr233, 3) |
| 42 | outs.append(Conv2D('conv233b', x3, nr233, 3, strides=stride)) |
| 43 | |
| 44 | if pooltype == 'max': |
| 45 | x4 = MaxPooling('mpool', x, 3, stride, padding='SAME') |
| 46 | else: |
| 47 | assert pooltype == 'avg' |
| 48 | x4 = AvgPooling('apool', x, 3, stride, padding='SAME') |
| 49 | if nrpool != 0: # pool + passthrough if nrpool == 0 |
| 50 | x4 = Conv2D('poolproj', x4, nrpool, 1) |
| 51 | outs.append(x4) |
| 52 | return tf.concat(outs, 3, name='concat') |
| 53 | |
| 54 | with argscope(Conv2D, activation=BNReLU, use_bias=False): |
| 55 | l = (LinearWrap(image) |
| 56 | .Conv2D('conv0', 64, 7, strides=2) |
| 57 | .MaxPooling('pool0', 3, 2, padding='SAME') |
| 58 | .Conv2D('conv1', 64, 1) |
| 59 | .Conv2D('conv2', 192, 3) |
| 60 | .MaxPooling('pool2', 3, 2, padding='SAME')()) |
| 61 | # 28 |
| 62 | l = inception('incep3a', l, 64, 64, 64, 64, 96, 32, 'avg') |
| 63 | l = inception('incep3b', l, 64, 64, 96, 64, 96, 64, 'avg') |
| 64 | l = inception('incep3c', l, 0, 128, 160, 64, 96, 0, 'max') |
| 65 | |
| 66 | br1 = (LinearWrap(l) |
| 67 | .Conv2D('loss1conv', 128, 1) |
| 68 | .FullyConnected('loss1fc', 1024, activation=tf.nn.relu) |
| 69 | .FullyConnected('loss1logit', 1000, activation=tf.identity)()) |
| 70 | loss1 = tf.nn.sparse_softmax_cross_entropy_with_logits(logits=br1, labels=label) |
| 71 | loss1 = tf.reduce_mean(loss1, name='loss1') |
| 72 | |
| 73 | # 14 |
| 74 | l = inception('incep4a', l, 224, 64, 96, 96, 128, 128, 'avg') |
| 75 | l = inception('incep4b', l, 192, 96, 128, 96, 128, 128, 'avg') |
| 76 | l = inception('incep4c', l, 160, 128, 160, 128, 160, 128, 'avg') |
| 77 | l = inception('incep4d', l, 96, 128, 192, 160, 192, 128, 'avg') |
| 78 | l = inception('incep4e', l, 0, 128, 192, 192, 256, 0, 'max') |
| 79 | |
| 80 | br2 = Conv2D('loss2conv', l, 128, 1) |
| 81 | br2 = FullyConnected('loss2fc', br2, 1024, activation=tf.nn.relu) |
| 82 | br2 = FullyConnected('loss2logit', br2, 1000, activation=tf.identity) |
| 83 | loss2 = tf.nn.sparse_softmax_cross_entropy_with_logits(logits=br2, labels=label) |
| 84 | loss2 = tf.reduce_mean(loss2, name='loss2') |
| 85 |
no test coverage detected