Caffe2 - Python API
A deep learning, cross platform ML framework
test_util.py
1 # Copyright (c) 2016-present, Facebook, Inc.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 ##############################################################################
15 
16 ## @package test_util
17 # Module caffe2.python.test_util
18 from __future__ import absolute_import
19 from __future__ import division
20 from __future__ import print_function
21 from __future__ import unicode_literals
22 import numpy as np
23 from caffe2.python import core, workspace
24 
25 import unittest
26 
27 
28 def rand_array(*dims):
29  # np.random.rand() returns float instead of 0-dim array, that's why need to
30  # do some tricks
31  return np.array(np.random.rand(*dims) - 0.5).astype(np.float32)
32 
33 
34 class TestCase(unittest.TestCase):
35  @classmethod
36  def setUpClass(cls):
37  workspace.GlobalInit([
38  'caffe2',
39  '--caffe2_log_level=0',
40  ])
41  # clear the default engines settings to separate out its
42  # affect from the ops tests
43  core.SetEnginePref({}, {})
44 
45  def setUp(self):
46  self.ws = workspace.C.Workspace()
47  workspace.ResetWorkspace()
48 
49  def tearDown(self):
50  workspace.ResetWorkspace()