def test_generate_arrays_no_data(self): """ Test that generation method correctly returns an empty iterable when no data is passed. """ g = CaffeDescriptorGenerator(self.dummy_net_topo_elem, self.dummy_caffe_model_elem, self.dummy_img_mean_elem, return_layer='fc', use_gpu=False) r = list(g._generate_arrays([])) assert r == []
def test_generate_arrays_from_url_hopper_description(self): # Caffe AlexNet interaction test (Grace Hopper image) # This is a long test since it has to download data for remote URIs d = CaffeDescriptorGenerator( self.alexnet_prototxt_elem, self.alexnet_caffemodel_elem, self.image_mean_proto_elem, return_layer='fc7', use_gpu=False, ) hopper_elem = DataFileElement(self.hopper_image_fp, readonly=True) expected_descr = numpy.load(self.hopper_alexnet_fc7_descr_fp) descr_list = list(d._generate_arrays([hopper_elem])) assert len(descr_list) == 1 descr = descr_list[0] numpy.testing.assert_allclose(descr, expected_descr, atol=1e-4)
def test_generate_arrays_dummy_model(self): # Caffe dummy network interaction test Grace Hopper image) # Construct network with an empty model just to see that our # interaction with the Caffe API is successful. We expect a # zero-valued descriptor vector. g = CaffeDescriptorGenerator(self.dummy_net_topo_elem, self.dummy_caffe_model_elem, self.dummy_img_mean_elem, return_layer='fc', use_gpu=False) d_list = list( g._generate_arrays( [DataFileElement(self.hopper_image_fp, readonly=True)])) assert len(d_list) == 1 d = d_list[0] self.assertAlmostEqual(d.sum(), 0., 12)