2 Copyright (c) 2018-2019 Intel Corporation
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
8 http://www.apache.org/licenses/LICENSE-2.0
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
21 from mo.front.caffe.extractors.scale import scale_ext
22 from mo.front.common.partial_infer.elemental import copy_shape_infer
23 from mo.utils.unittest.extractors import FakeMultiParam, FakeModelLayer
27 def __init__(self, val, bottom2=False):
28 self.scale_param = val
30 self.bottom = {"bottom1", "bottom2"}
32 self.bottom = {"bottom1"}
35 class TestScale(unittest.TestCase):
36 def test_scale_ext(self):
37 mean_blob = np.array([1., 2.])
38 variance_blob = np.array([3., 4.])
39 blobs = [mean_blob, variance_blob]
46 res = scale_ext(FakeProtoLayer(FakeMultiParam(params)), FakeModelLayer(blobs))
51 'infer': copy_shape_infer,
53 'biases': variance_blob,
64 if i in ('weights', 'biases'):
65 np.testing.assert_array_equal(res[i], exp_res[i])
67 self.assertEqual(res[i], exp_res[i])
69 def test_scale_2inputs_ext(self):
76 res = scale_ext(FakeProtoLayer(FakeMultiParam(params), True), None)
81 'infer': copy_shape_infer,
84 self.assertEqual(res[i], exp_res[i])
86 def test_scale_2inputs_bias_ext(self):
87 variance_blob = np.array([3., 4.])
88 blobs = [variance_blob]
96 res = scale_ext(FakeProtoLayer(FakeMultiParam(params), True), FakeModelLayer(blobs))
101 'infer': copy_shape_infer,
102 'biases': variance_blob,
110 np.testing.assert_array_equal(res[i], exp_res[i])
112 self.assertEqual(res[i], exp_res[i])
114 def test_create_default_weights(self):
116 There are situations when scale layer doesn't have weights and biases. This test checks that if they are not
117 available in the caffemodel file then default values [1] and [0] are generated.
119 scale_blob = np.array([1])
120 bias_blob = np.array([0])
127 res = scale_ext(FakeProtoLayer(FakeMultiParam(params)), None)
130 'type': 'ScaleShift',
132 'infer': copy_shape_infer,
133 'weights': scale_blob,
144 self.assertDictEqual(exp_res, res)