Ejemplo n.º 1
0
def test_bs_PCA_fit():
    img_path_placeholder, ending_points, SESS \
            = _get_cate_seed0_ending_points_sess(
                    64,
                    '/mnt/fs4/chengxuz/brainscore_model_caches/cate_aug/res18/exp_seed0_bn_wd/checkpoint-505505')
    identifier = 'test-cate-bn-wd-pca'
    activations_model = TensorflowSlimWrapper(
            identifier=identifier, labels_offset=0,
            endpoints=ending_points, inputs=img_path_placeholder, 
            session=SESS)

    LayerPCA.hook(activations_model, n_components=1000)
    #benchmark = bench.load('dicarlo.Majaj2015.IT-pls')
    benchmark = bench.load('dicarlo.Majaj2015.V4-pls')
    all_layers = ['encode_%i' % i for i in range(1, 10)]

    model_scores = LayerScores(
            identifier, 
            activations_model=activations_model,
            )
    score = model_scores(
            benchmark=benchmark, 
            layers=all_layers,
            )
    print(score)
Ejemplo n.º 2
0
def test_bs_fit():
    img_path_placeholder, ending_points, SESS \
            = _get_cate_seed0_ending_points_sess(64)

    #identifier = 'test-la-seed0'
    #identifier = 'test-la-seed0-2'
    #identifier = 'test-cate-seed1'
    #identifier = 'test-cate-seed0-mask-2'
    #identifier = 'test-cate-seed0-mask-midvar'
    #identifier = 'test-cate-seed0-mask-midvar-smwd'
    #identifier = 'test-cate-seed0-mask-midvar-params'
    #identifier = 'test-cate-seed0-mask-midvar-faster'
    #identifier = 'test-cate-seed0-mask-midvar-faster-debug'
    #identifier = 'test-cate-seed0-mask-midvar-faster-debug-2'
    #identifier = 'test-cate-seed0-mask-final-2'
    #identifier = 'test-cate-seed0-mask-final-e12'
    #identifier = 'test-cate-seed0-mask-final-e1-nolap'
    #identifier = 'test-cate-seed0-mask-final-e1-nolap-3'
    identifier = 'test-cate-seed0-mask-final-all-test-2'
    activations_model = TensorflowSlimWrapper(
            identifier=identifier, labels_offset=0,
            endpoints=ending_points, inputs=img_path_placeholder, 
            session=SESS)

    #all_params = []
    #for each_ls in [0.1, 0.01]:
    #    for each_ld in [0.1, 0.01]:
    #        all_params.append(json.dumps([[], {'ls': each_ls, 'ld': each_ld}]))

    #all_params = [
    #        json.dumps([[], {'ls': 0.1, 'ld': 0.1}]), 
    #        json.dumps([[], {'ls': 0.01, 'ld': 0.01}])]

    all_params = [
            json.dumps([[], {
                'with_corr_loss': True,
                'with_lap_loss': False,
                'adam_eps': 0.1,
                'max_epochs': 50, 
                'decay_rate': 35,
                }]), 
            #json.dumps([[], {'max_epochs': 50, 'decay_rate': 35, 'ls': 0.01, 'ld': 0.01}]), 
            #json.dumps([[], {'max_epochs': 60, 'decay_rate': 45}]), 
            ]

    layer_and_params = []
    #all_layers = ['encode_%i' % i for i in range(1, 10)]
    all_layers = ['encode_1']
    for layer in all_layers:
        _model_scores = ParamScores(
                identifier, 
                activations_model=activations_model)
        _score = _model_scores(
                #benchmark_builder=DicarloMajaj2015ITLowMidVarMask, 
                benchmark_builder=DicarloMajaj2015ITMaskParams, 
                params=all_params,
                layer=layer,
                )
        print(_score)
Ejemplo n.º 3
0
 def _build_activations_model(self, batch_size):
     self.activations_model = TensorflowSlimWrapper(
         identifier=self.identifier,
         labels_offset=0,
         endpoints=self.ending_points,
         inputs=self.img_path_placeholder,
         session=self.SESS,
         batch_size=batch_size)
     return self.activations_model
Ejemplo n.º 4
0
    def init(identifier, preprocessing_type, image_size, net_name=None, labels_offset=1, batch_size=64,
             model_ctr_kwargs=None):
        import tensorflow as tf
        from nets import nets_factory

        tf.compat.v1.reset_default_graph()
        placeholder = tf.compat.v1.placeholder(dtype=tf.string, shape=[batch_size])
        preprocess = TFSlimModel._init_preprocessing(placeholder, preprocessing_type, image_size=image_size)

        net_name = net_name or identifier
        model_ctr = nets_factory.get_network_fn(net_name, num_classes=labels_offset + 1000, is_training=False)
        logits, endpoints = model_ctr(preprocess, **(model_ctr_kwargs or {}))
        if 'Logits' in endpoints:  # unify capitalization
            endpoints['logits'] = endpoints['Logits']
            del endpoints['Logits']

        session = tf.compat.v1.Session()
        TFSlimModel._restore_imagenet_weights(identifier, session)
        wrapper = TensorflowSlimWrapper(identifier=identifier, endpoints=endpoints, inputs=placeholder, session=session,
                                        batch_size=batch_size, labels_offset=labels_offset)
        wrapper.image_size = image_size
        return wrapper