Exemplo n.º 1
0
def model(x, H, reuse, is_training=True):
    if H['inception'] == 1:
        with slim.arg_scope(inception_v1.inception_v1_arg_scope()):
            _, T = inception_v1.inception_v1(
                x,
                is_training=is_training,
                num_classes=1001,
                dropout_keep_prob=H['dense_dropout'],
                input_dropout=H['input_dropout'],
                spatial_squeeze=False,
                reuse=reuse)
        coarse_feat = T[H['coarse_feat']]

        # fine feat can be used to reinspect input
        early_feat = T[H['early_feat']]
        early_feat_channels = 480
    elif H['inception'] == 3:
        with slim.arg_scope(inception_v3.inception_v3_arg_scope()):
            _, T = inception_v3.inception_v3(x,
                                             is_training=is_training,
                                             num_classes=1001,
                                             dropout_keep_prob=0.8,
                                             spatial_squeeze=False,
                                             reuse=reuse)
        coarse_feat = T['Mixed_5b']

        # fine feat can be used to reinspect input
        attention_lname = H.get('attention_lname', 'Mixed_3b')
        early_feat = T[attention_lname]
        early_feat_channels = 480

    return coarse_feat, early_feat, early_feat_channels
Exemplo n.º 2
0
 def testModelHasExpectedNumberOfParameters(self):
     batch_size = 5
     height, width = 224, 224
     inputs = tf.random_uniform((batch_size, height, width, 3))
     with slim.arg_scope(inception_v1.inception_v1_arg_scope()):
         inception_v1.inception_v1_base(inputs)
     total_params, _ = slim.model_analyzer.analyze_vars(
         slim.get_model_variables())
     self.assertAlmostEqual(5607184, total_params)
Exemplo n.º 3
0
def model(x, H, reuse, is_training=True):
    with slim.arg_scope(inception.inception_v1_arg_scope()):
        _, T = inception.inception_v1(x,
                                      is_training=is_training,
                                      num_classes=1001,
                                      spatial_squeeze=False,
                                      reuse=reuse)
    coarse_feat = T['Mixed_5b']

    # fine feat can be used to reinspect input
    attention_lname = H.get('attention_lname', 'Mixed_3b')
    early_feat = T[attention_lname]
    early_feat_channels = 480

    return coarse_feat, early_feat, early_feat_channels
Exemplo n.º 4
0
def model(x, H, reuse, is_training=True):
    with slim.arg_scope(inception.inception_v1_arg_scope()):
        _, T = inception.inception_v1(x,
                                      is_training=is_training,
                                      num_classes=1001,
                                      spatial_squeeze=False,
                                      reuse=reuse)
    coarse_feat = T['Mixed_5b']

    # fine feat can be used to reinspect input
    attention_lname = H.get('attention_lname', 'Mixed_3b')
    early_feat = T[attention_lname]
    early_feat_channels = 480

    return coarse_feat, early_feat, early_feat_channels
def model(x, H, reuse, is_training=True):
    if H['slim_basename'] == 'resnet_v1_101':
        with slim.arg_scope(resnet.resnet_arg_scope()):
            _, T = resnet.resnet_v1_101(x,
                                        is_training=is_training,
                                        num_classes=1000,
                                        reuse=reuse)
    elif H['slim_basename'] == 'InceptionV1':
        with slim.arg_scope(inception.inception_v1_arg_scope()):
            _, T = inception.inception_v1(x,
                                          is_training=is_training,
                                          num_classes=1001,
                                          spatial_squeeze=False,
                                          reuse=reuse)
    #print '\n'.join(map(str, [(k, v.op.outputs[0].get_shape()) for k, v in T.iteritems()]))

    coarse_feat = T[H['slim_top_lname']][:, :, :, :H['later_feat_channels']]
    assert coarse_feat.op.outputs[0].get_shape()[3] == H['later_feat_channels']

    # fine feat can be used to reinspect input
    attention_lname = H.get('slim_attention_lname', 'Mixed_3b')
    early_feat = T[attention_lname]

    return coarse_feat, early_feat
Exemplo n.º 6
0
                                           tf.FixedLenFeature([], tf.int64),
                                           "image":
                                           tf.FixedLenFeature([], tf.string)
                                       })
    img = tf.decode_raw(features["image"], tf.uint8)
    img = tf.reshape(img, [image_pixels, image_pixels, 3])
    img = tf.cast(img, tf.float32)
    label = tf.cast(features["label"], tf.int32)
    return img, label


images = tf.placeholder(tf.float32, [None, image_pixels, image_pixels, 3],
                        name="input/x_input")
labels = tf.placeholder(tf.int64, [None], name="input/y_input")

with slim.arg_scope(inception_v1_arg_scope()):
    logits, end_points = inception_v1(images,
                                      num_classes=classes,
                                      is_training=False)

correct_prediction = tf.equal(labels,
                              tf.argmax(end_points['Predictions'], 1),
                              name="correct_prediction")
accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32),
                          name="accuracy")

with tf.Session() as sess:
    ckpt = tf.train.get_checkpoint_state("ckpt")
    if ckpt:
        print(ckpt.model_checkpoint_path)
        tf.train.Saver().restore(sess, ckpt.model_checkpoint_path)