Пример #1
0
    def __init__(self, net_file=None, meta_file=None):
        """Initializes DecafNet.

        Input:
            net_file: the trained network file.
            meta_file: the meta information for images.
        """
        logging.info('Initializing decafnet...')
        try:
            if not net_file:
                # use the internal decafnet file.
                net_file = _JEFFNET_FILE
            if not meta_file:
                # use the internal meta file.
                meta_file = _META_FILE
            cuda_decafnet = pickle.load(open(net_file))
            meta = pickle.load(open(meta_file))
        except IOError:
            raise RuntimeError('Cannot find DecafNet files.')
        # First, translate the network
        self._net = translator.translate_cuda_network(
            cuda_decafnet, {'data': (INPUT_DIM, INPUT_DIM, 3)})
        # Then, get the labels and image means.
        self.label_names = meta['label_names']
        self._data_mean = translator.img_cudaconv_to_decaf(
            meta['data_mean'], 256, 3)
        logging.info('Jeffnet initialized.')
        return
    def __init__(self, net_file=None, meta_file=None):
        """Initializes DecafNet.

        Input:
            net_file: the trained network file.(normally,['model_state']['layers'])
            meta_file: the meta information for images.
        """
        logging.info('Initializing decafnet...')
        try:
            if not net_file:
                # use the internal decafnet file.
                net_file = _KITNET_FILE
            if not meta_file:
                # use the internal meta file.
                meta_file = _META_FILE
            cuda_decafnet = pickle.load(open(net_file,'rb'))['model_state']['layers']
            meta = pickle.load(open(meta_file,'rb'))
        except IOError:
            raise RuntimeError('Cannot find DecafNet files.')
        # First, translate the network
        self._net = translator.translate_cuda_network(
            cuda_decafnet, {'data': (INPUT_DIM, 1)})
        # Then, get the labels and image means.
        self.label_names = meta['label_names']
        self._data_mean =  meta['data_mean']
        logging.info('Kitnet initialized.')
        return
Пример #3
0
def load_net(fname):
    cudaconv_net = IGPUModel.load_checkpoint(fname)
    layers = cudaconv_net["model_state"]["layers"]

    #Note, data dimensions are hardcoded here - not sure we have that info in the cudaconv object?
    decafnet = translator.translate_cuda_network(layers, {'data': (32, 32, 3)})
    return decafnet
Пример #4
0
    def __init__(self, net_file=None, meta_file=None):
        """Initializes DecafNet.

        Input:
            net_file: the trained network file.
            meta_file: the meta information for images.
        """
        logging.info('Initializing decafnet...')
        try:
            if not net_file:
                # use the internal decafnet file.
                net_file = _JEFFNET_FILE
            if not meta_file:
                # use the internal meta file.
                meta_file = _META_FILE
            cuda_decafnet = pickle.load(open(net_file))
            meta = pickle.load(open(meta_file))
        except IOError:
            raise RuntimeError('Cannot find DecafNet files.')
        # First, translate the network
        self._net = translator.translate_cuda_network(
            cuda_decafnet, {'data': (INPUT_DIM, INPUT_DIM, 3)})
        # Then, get the labels and image means.
        self.label_names = meta['label_names']
        self._data_mean = translator.img_cudaconv_to_decaf(
            meta['data_mean'], 256, 3)
        logging.info('Jeffnet initialized.')
        return
Пример #5
0
def load_net(fname):
    cudaconv_net = IGPUModel.load_checkpoint(fname)
    layers = cudaconv_net["model_state"]["layers"]
    
    #Note, data dimensions are hardcoded here - not sure we have that info in the cudaconv object?
    decafnet = translator.translate_cuda_network(layers, {'data': (32, 32, 3)})
    return decafnet
Пример #6
0
def load_from_convnet(filename):
    cudaconv_net = IGPUModel.load_checkpoint(filename)
    layers = cudaconv_net["model_state"]["layers"]
    data_layer = [l for l in layers if l["name"] == "data"][0]
    data_consumer = [l for l in layers if data_layer in l.get("inputLayers", [])][0]
    input_dim = int(sqrt(data_consumer["imgPixels"][0]))  # The width/height of the square images
    input_channels = data_consumer["channels"][0]  # The number of channels in the input images
    return translator.translate_cuda_network(layers, {"data": (input_dim, input_dim, input_channels)})
Пример #7
0
 def setUp(self):
     self._layers = pickle.load(
         open(os.path.join(_TEST_DATA_DIR, 'layers.pickle')))
     self._data = pickle.load(
         open(os.path.join(_TEST_DATA_DIR, 'data', 'data_batch_5')))
     self._decaf_data = translator.imgs_cudaconv_to_decaf(
         self._data['data'][:_BATCH_SIZE], 32, 3)
     #self._decaf_labels = self._data['labels'].flatten()[:_BATCH_SIZE]
     #self._decaf_labels = self._decaf_labels.astype(np.int)
     self._output_shapes = {'data': (32, 32, 3), 'labels': -1}
     self._net = translator.translate_cuda_network(self._layers,
                                                   self._output_shapes)
     self._net.predict(data=self._decaf_data)
Пример #8
0
def load_from_convnet(filename):
    cudaconv_net = IGPUModel.load_checkpoint(filename)
    layers = cudaconv_net["model_state"]["layers"]
    data_layer = [l for l in layers if l['name'] == 'data'][0]
    data_consumer = [
        l for l in layers if data_layer in l.get('inputLayers', [])
    ][0]
    input_dim = int(sqrt(data_consumer['imgPixels']
                         [0]))  # The width/height of the square images
    input_channels = data_consumer['channels'][
        0]  # The number of channels in the input images
    return translator.translate_cuda_network(
        layers, {'data': (input_dim, input_dim, input_channels)})
 def setUp(self):
     self._layers = pickle.load(open(os.path.join(_TEST_DATA_DIR,
                                                  'layers.pickle')))
     self._data = pickle.load(open(os.path.join(_TEST_DATA_DIR,
                                                'data',
                                                'data_batch_5')))
     self._decaf_data = translator.imgs_cudaconv_to_decaf(
         self._data['data'][:_BATCH_SIZE], 32, 3)
     #self._decaf_labels = self._data['labels'].flatten()[:_BATCH_SIZE]
     #self._decaf_labels = self._decaf_labels.astype(np.int)
     self._output_shapes = {'data': (32, 32, 3), 'labels': -1}
     self._net = translator.translate_cuda_network(
         self._layers, self._output_shapes)
     self._net.predict(data=self._decaf_data)