Пример #1
0
 def test_fill_non_constant_input_with_specific_mapping_not_all_image_in_batch_matched_raise_config_error(self):
     input_feeder = InputFeeder([{'name': 'input', 'type': 'INPUT', 'value': '0+'}], {'input': InputInfo_test(shape=(1, 3, 10, 10))}, {})
     with pytest.raises(ConfigError):
         input_feeder.fill_non_constant_inputs([
             DataRepresentation(np.zeros((10, 10, 3)), identifier='0'),
             DataRepresentation(np.zeros((10, 10, 3)), identifier='1')
         ])
 def test_fill_non_constant_inputs_with_specific_mapping_not_all_image_in_batch_matched_raise_config_error(
         self):
     input_feeder = InputFeeder([{
         'name': 'input1',
         'type': 'INPUT',
         'value': '0'
     }, {
         'name': 'input2',
         'type': 'INPUT',
         'value': '1'
     }], {
         'input1': (1, 3, 10, 10),
         'input2': (1, 3, 10, 10)
     }, {})
     with pytest.raises(ConfigError):
         input_feeder.fill_non_constant_inputs([
             DataRepresentation(
                 [np.zeros((10, 10, 3)),
                  np.ones((10, 10, 3))],
                 identifier=['0', '1']),
             DataRepresentation(
                 [np.zeros((10, 10, 3)),
                  np.ones((10, 10, 3))],
                 identifier=['0', '2'])
         ])
 def test_fill_non_constant_inputs_with_specific_mapping_batch_2(self):
     input_feeder = InputFeeder(
         [{
             'name': 'input1',
             'type': 'INPUT',
             'value': '0'
         }, {
             'name': 'input2',
             'type': 'INPUT',
             'value': '1'
         }], {
             'input1': InputInfo_test(shape=(1, 3, 10, 10)),
             'input2': InputInfo_test(shape=(1, 3, 10, 10))
         }, {})
     result = input_feeder.fill_non_constant_inputs([
         DataRepresentation([np.zeros(
             (10, 10, 3)), np.ones((10, 10, 3))],
                            identifier=['0', '1']),
         DataRepresentation([np.zeros(
             (10, 10, 3)), np.ones((10, 10, 3))],
                            identifier=['0', '1'])
     ])[0]
     expected_data = [np.zeros((2, 3, 10, 10)), np.ones((2, 3, 10, 10))]
     assert 'input1' in result
     assert np.array_equal(result['input1'], expected_data[0])
     assert 'input2' in result
     assert np.array_equal(result['input2'], expected_data[1])
Пример #4
0
 def test_fill_non_constant_input_with_specific_mapping_several_image_matched(self):
     inputs = {'data': (1, 3, 10, 10)}
     input_feeder = InputFeeder([{'name': 'input', 'type': 'INPUT', 'value': '.'}], {'input': InputInfo_test(shape=(1, 3, 10, 10))}, lambda name: inputs[name])
     result = input_feeder.fill_non_constant_inputs([DataRepresentation([np.zeros((10, 10, 3)), np.ones((10, 10, 3))], identifier=['0', '1'])])[0]
     expected_data = np.zeros((1, 3, 10, 10))
     assert 'input' in result
     assert np.array_equal(result['input'], expected_data)
Пример #5
0
 def test_fill_non_constant_input_with_one_input_without_specific_mapping_batch_1(self):
     inputs = {'data': (1, 3, 10, 10)}
     input_feeder = InputFeeder([], {'input': InputInfo_test(shape=(1, 3, 10, 10))}, lambda name: inputs[name])
     result = input_feeder.fill_non_constant_inputs([DataRepresentation(np.zeros((10, 10, 3)), identifier='0')])[0]
     expected_data = np.zeros((1, 3, 10, 10))
     assert 'input' in result
     assert np.array_equal(result['input'], expected_data)
Пример #6
0
 def test_fill_non_constant_inputs_without_specific_mapping_batch_1(self):
     input_feeder = InputFeeder([], { 'input1': InputInfo_test(shape=(1, 3, 10, 10)), 'input2': InputInfo_test(shape=(1, 3, 10, 10))}, {})
     result = input_feeder.fill_non_constant_inputs([DataRepresentation(np.zeros((10, 10, 3)), identifier='0')])[0]
     expected_data = np.zeros((1, 3, 10, 10))
     assert 'input1' in result
     assert np.array_equal(result['input1'], expected_data)
     assert 'input2' in result
     assert np.array_equal(result['input2'], expected_data)
Пример #7
0
 def test_fill_non_const_input_with_multi_infer_data_batch_1(self):
     input_feeder = InputFeeder({}, {'input': (1, 3, 10, 10)}, {})
     result = input_feeder.fill_non_constant_inputs([
         DataRepresentation([np.zeros((10, 10, 3)), np.ones((10, 10, 3))], {'multi_infer': True}, identifier='0')
     ])
     expected = [{'input': np.zeros((1, 3, 10, 10))}, {'input': np.ones((1, 3, 10, 10))}]
     assert len(result) == len(expected)
     assert np.array_equal(result[0]['input'], expected[0]['input'])
     assert np.array_equal(result[1]['input'], expected[1]['input'])
Пример #8
0
 def test_fill_non_constant_input_with_specific_mapping_batch_2(self):
     input_feeder = InputFeeder([{'name': 'input', 'type': 'INPUT', 'value': '.'}], {'input': InputInfo_test(shape=(1, 3, 10, 10))}, {})
     result = input_feeder.fill_non_constant_inputs([
         DataRepresentation(np.zeros((10, 10, 3)), identifier='0'),
         DataRepresentation(np.zeros((10, 10, 3)), identifier='1')
     ])[0]
     expected_data = np.zeros((2, 3, 10, 10))
     assert 'input' in result
     assert np.array_equal(result['input'], expected_data)
 def test_set_input_precision_for_non_constant_input(self):
     input_feeder = InputFeeder([{
         'name': 'input_u8',
         'type': 'INPUT',
         'precision': 'U8'
     }], {'input_u8': (1, 3, 10, 10)}, {})
     result = input_feeder.fill_non_constant_inputs([
         DataRepresentation(np.zeros((10, 10, 3)), identifier='0'),
     ])
     expected = [{'input_u8': np.zeros((1, 3, 10, 10), dtype=np.uint8)}]
     assert len(result) == len(expected)
     assert np.array_equal(result[0]['input_u8'], expected[0]['input_u8'])
     assert result[0]['input_u8'].dtype == expected[0]['input_u8'].dtype
Пример #10
0
 def test_set_input_precision_for_image_info_input(self):
     input_feeder = InputFeeder(
         [{'name': 'im_info', 'type': 'IMAGE_INFO', 'precision': 'U8'}],
         {'input': (1, 3, 10, 10), 'im_info': (1, 3)}, lambda name: [1, 3])
     result = input_feeder.fill_non_constant_inputs([
         DataRepresentation(
             np.zeros((10, 10, 3)),
             identifier='0'
         ),
     ])
     expected = [{'input': np.zeros((1, 3, 10, 10)), 'im_info': np.array([[10, 10, 1]], dtype=np.uint8)}]
     assert len(result) == len(expected)
     assert np.array_equal(result[0]['input'], expected[0]['input'])
     assert result[0]['input'].dtype == expected[0]['input'].dtype
     assert np.array_equal(result[0]['im_info'], expected[0]['im_info'])
     assert result[0]['im_info'].dtype == expected[0]['im_info'].dtype