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)
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)
def _testSingleLayer(self, decaf_name, cuda_name, reshape_size=0, reshape_channels=0, decimal=6): output = self._net.feature(self._net.provides[decaf_name][0]) self.assertEqual(output.shape[1:], self._output_shapes[decaf_name]) ref_data = pickle.load(open( os.path.join(_TEST_DATA_DIR, cuda_name, 'data_batch_5'))) ref_data = ref_data['data'][:_BATCH_SIZE] if reshape_size: ref_data = translator.imgs_cudaconv_to_decaf( ref_data, reshape_size, reshape_channels) # We rescale the data so that the decimal specified would also count # the original scale of the data. maxval = ref_data.max() ref_data /= maxval output /= maxval #print 'data range: [%f, %f], max diff: %f' % ( # ref_data.min(), ref_data.max(), np.abs(ref_data - output).max()) np.testing.assert_array_almost_equal(ref_data, output, decimal)
def _testSingleLayer(self, decaf_name, cuda_name, reshape_size=0, reshape_channels=0, decimal=6): output = self._net.feature(self._net.provides[decaf_name][0]) self.assertEqual(output.shape[1:], self._output_shapes[decaf_name]) ref_data = pickle.load( open(os.path.join(_TEST_DATA_DIR, cuda_name, 'data_batch_5'))) ref_data = ref_data['data'][:_BATCH_SIZE] if reshape_size: ref_data = translator.imgs_cudaconv_to_decaf( ref_data, reshape_size, reshape_channels) # We rescale the data so that the decimal specified would also count # the original scale of the data. maxval = ref_data.max() ref_data /= maxval output /= maxval #print 'data range: [%f, %f], max diff: %f' % ( # ref_data.min(), ref_data.max(), np.abs(ref_data - output).max()) np.testing.assert_array_almost_equal(ref_data, output, decimal)