def test_compute_descriptor_dummy_model(self): # Caffe dummy network interaction test Lenna 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_fp, self.dummy_caffe_model_fp, self.dummy_img_mean_fp, return_layer='fc', use_gpu=False) d = g.compute_descriptor(from_uri(self.lenna_image_fp)) self.assertAlmostEqual(d.vector().sum(), 0., 12)
def test_compute_descriptor_dummy_model(self): # Caffe dummy network interaction test Lenna 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_fp, self.dummy_caffe_model_fp, self.dummy_img_mean_fp, return_layer='fc', use_gpu=False) d = g.compute_descriptor(from_uri(self.lenna_image_fp)) nose.tools.assert_almost_equal(d.vector().sum(), 0., 12)
def test_compute_descriptor_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 = d.compute_descriptor(hopper_elem).vector() numpy.testing.assert_allclose(descr, expected_descr, atol=1e-4)
def test_compute_descriptor_dummy_model(self): # Caffe dummy network interaction test Lenna 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 = g.compute_descriptor( DataFileElement(self.hopper_image_fp, readonly=True)) self.assertAlmostEqual(d.vector().sum(), 0., 12)
def test_compute_descriptor_from_url_lenna_description(self): # Caffe AlexNet interaction test (Lenna image) # This is a long test since it has to download data for remote URIs d = CaffeDescriptorGenerator( self.www_uri_alexnet_prototxt, self.www_uri_alexnet_caffemodel, self.www_uri_image_mean_proto, return_layer='fc7', use_gpu=False, ) lenna_elem = from_uri(self.lenna_image_fp) expected_descr = numpy.load(self.lenna_alexnet_fc7_descr_fp) descr = d.compute_descriptor(lenna_elem).vector() numpy.testing.assert_allclose(descr, expected_descr, atol=1e-5)
def test_compute_descriptor_from_url_lenna_description(self): # Caffe AlexNet interaction test (Lenna image) # This is a long test since it has to download data for remote URIs d = CaffeDescriptorGenerator( self.www_uri_alexnet_prototxt, self.www_uri_alexnet_caffemodel, self.www_uri_image_mean_proto, return_layer='fc7', use_gpu=False, ) lenna_elem = from_uri(self.lenna_image_fp) expected_descr = numpy.load(self.lenna_alexnet_fc7_descr_fp) descr = d.compute_descriptor(lenna_elem).vector() numpy.testing.assert_allclose(descr, expected_descr, atol=1e-5)
""" Test computing a descriptor on something. """ from smqtk.algorithms.descriptor_generator.caffe_descriptor import CaffeDescriptorGenerator from smqtk.representation.data_element.file_element import DataFileElement e = DataFileElement("/usr/local/lib/python2.7/dist-packages/smqtk/tests/data/" "Lenna.png") gen = CaffeDescriptorGenerator( "/home/smqtk/caffe/msra_resnet/ResNet-50-deploy.prototxt", "/home/smqtk/caffe/msra_resnet/ResNet-50-model.caffemodel", "/home/smqtk/caffe/msra_resnet/ResNet_mean.binaryproto", return_layer="pool5", use_gpu=False, load_truncated_images=True) # Uses default DescriptorMemoryElement factory. d = gen.compute_descriptor(e) assert d.vector() is not None
""" Test computing a descriptor on something. """ from smqtk.algorithms.descriptor_generator.caffe_descriptor import CaffeDescriptorGenerator from smqtk.representation.data_element.file_element import DataFileElement e = DataFileElement("/usr/local/lib/python2.7/dist-packages/smqtk/tests/data/" "Lenna.png") gen = CaffeDescriptorGenerator( "/home/smqtk/caffe/msra_resnet/ResNet-50-deploy.prototxt", "/home/smqtk/caffe/msra_resnet/ResNet-50-model.caffemodel", "/home/smqtk/caffe/msra_resnet/ResNet_mean.binaryproto", return_layer="pool5", use_gpu=False, load_truncated_images=True ) # Uses default DescriptorMemoryElement factory. d = gen.compute_descriptor(e) assert d.vector() is not None