Exemplo n.º 1
0
 def get_vgg16_output(self, step2h5list):
     res = h5util.read_from_h5(step2h5list['vgg16_output'][0])
     meta = res['meta']
     label = res['label']
     del res['meta']
     del res['label']
     return res, meta, label
Exemplo n.º 2
0
def model_layers(data_iter, config, pipeline, step2h5list, output_files):
    data_stats = h5util.read_from_h5(step2h5list['data_stats'][0])
    channel_mean = data_stats['channel_mean']
    datalen = data_stats['datalen']
    model = pipeline.vgg16()
    prepare_for_vgg16 = pipeline.prepare_for_vgg16
    imgprep_config = pipeline.get_config('imgprep')
    vgg16 = pipeline.vgg16()
    h5out = h5py.File(output_files[0], 'w')
    idx = 0
    layer_names = ['fc1', 'fc2']
    name2dset = {}
    all_meta = []
    for X, Y, meta in data_iter:
        all_meta.append(meta)
        img = X[0]
        prep_img = prepare_for_vgg16(img,
                                     imgprep_config,
                                     channel_mean=channel_mean)
        prep_img = np.reshape(prep_img, [1] + list(prep_img.shape))
        layers = vgg16.get_model_layers(sess=pipeline.session,
                                        imgs=prep_img,
                                        layer_names=layer_names)
        if idx == 0:
            for layer, name in zip(layers, layer_names):
                dset_shape = tuple([datalen] + list(layer.shape[1:]))
                name2dset[name] = h5out.create_dataset(name,
                                                       shape=dset_shape,
                                                       dtype=layer.dtype)
        for layer, name in zip(layers, layer_names):
            name2dset[name][idx, :] = layer[0, :]
        idx += 1
    h5util.write_meta(h5out, all_meta)
Exemplo n.º 3
0
 def get_datastat(self, name, step2h5list):
     if name in ['codeword_num_features']:
         if None is self._datastats_codewords:
             h5 = h5py.File(step2h5list['compute_vgg16_codewords'][0],'r')
             self._datastats_codewords = {}
             self._datastats_codewords['codeword_num_features'] = h5['codewords'].shape[1]
         return self._datastats_codewords['codeword_num_features']
     
     if None is self._datastats:
         self._datastats = h5util.read_from_h5(step2h5list['compute_channel_mean'][0])
     assert name in self._datastats, "name=%s not in datasats, keys are: %r" % (name, self._datastats.keys())
     return self._datastats[name]