from smqtk.algorithms.descriptor_generator import DescriptorGenerator from smqtk.algorithms.descriptor_generator.caffe_descriptor import \ caffe, CaffeDescriptorGenerator # Testing protected helper function # noinspection PyProtectedMember from smqtk.algorithms.descriptor_generator.caffe_descriptor import \ _process_load_img_array from smqtk.representation.data_element.file_element import DataFileElement from smqtk.representation.data_element.memory_element import DataMemoryElement from smqtk.representation.data_element.url_element import DataUrlElement from smqtk.utils.configuration import to_config_dict, configuration_test_helper from tests import TEST_DATA_DIR @unittest.skipUnless(CaffeDescriptorGenerator.is_usable(), reason="CaffeDescriptorGenerator is not usable in" "current environment.") class TestCaffeDesctriptorGenerator(unittest.TestCase): hopper_image_fp = os.path.join(TEST_DATA_DIR, 'grace_hopper.png') hopper_alexnet_fc7_descr_fp = os.path.join( TEST_DATA_DIR, 'Hopper.alexnet_fc7_output.npy') # Dummy Caffe configuration files + weights # - weights is actually an empty file (0 bytes), which caffe treats # as random/zero values (not sure exactly what's happening, but # always results in a zero-vector). dummy_net_topo_elem = DataFileElement(os.path.join( TEST_DATA_DIR, 'caffe.dummpy_network.prototxt'), readonly=True)
from smqtk.algorithms.descriptor_generator import DescriptorGenerator from smqtk.algorithms.descriptor_generator.caffe_descriptor import \ caffe, CaffeDescriptorGenerator # Testing protected helper function # noinspection PyProtectedMember from smqtk.algorithms.descriptor_generator.caffe_descriptor import \ _process_load_img_array from smqtk.representation.data_element.file_element import DataFileElement from smqtk.representation.data_element.memory_element import DataMemoryElement from smqtk.representation.data_element.url_element import DataUrlElement from smqtk.utils.configuration import to_config_dict from tests import TEST_DATA_DIR if CaffeDescriptorGenerator.is_usable(): class TestCaffeDesctriptorGenerator(unittest.TestCase): hopper_image_fp = get_sample_data('grace_hopper.png', asfileobj=False) hopper_alexnet_fc7_descr_fp = os.path.join( TEST_DATA_DIR, 'Hopper.alexnet_fc7_output.npy') # Dummy Caffe configuration files + weights # - weights is actually an empty file (0 bytes), which caffe treats # as random/zero values (not sure exactly what's happening, but # always results in a zero-vector). dummy_net_topo_elem = DataFileElement(os.path.join( TEST_DATA_DIR, 'caffe.dummpy_network.prototxt'), readonly=True) dummy_caffe_model_elem = DataFileElement(os.path.join(
import mock import numpy from smqtk.algorithms.descriptor_generator import get_descriptor_generator_impls from smqtk.algorithms.descriptor_generator.caffe_descriptor import \ caffe, CaffeDescriptorGenerator # Testing protected helper function # noinspection PyProtectedMember from smqtk.algorithms.descriptor_generator.caffe_descriptor import \ _process_load_img_array from smqtk.representation.data_element import from_uri from smqtk.representation.data_element.url_element import DataUrlElement from smqtk.tests import TEST_DATA_DIR if CaffeDescriptorGenerator.is_usable(): class TestCaffeDesctriptorGenerator (unittest.TestCase): lenna_image_fp = os.path.join(TEST_DATA_DIR, 'Lenna.png') lenna_alexnet_fc7_descr_fp = \ os.path.join(TEST_DATA_DIR, 'Lenna.alexnet_fc7_output.npy') # Dummy Caffe configuration files + weights # - weights is actually an empty file (0 bytes), which caffe treats # as random/zero values (not sure exactly what's happening, but # always results in a zero-vector). dummy_net_topo_fp = \ os.path.join(TEST_DATA_DIR, 'caffe.dummpy_network.prototxt') dummy_caffe_model_fp = \ os.path.join(TEST_DATA_DIR, 'caffe.empty_model.caffemodel')