()
| 25 | import unittest |
| 26 | |
| 27 | def setUpModule(): |
| 28 | # Do nothing if caffe and test data is not found |
| 29 | if not (CAFFE_FOUND and os.path.exists('data/testdata/caffe_translator')): |
| 30 | return |
| 31 | # We will do all the computation stuff in the global space. |
| 32 | caffenet = caffe_pb2.NetParameter() |
| 33 | caffenet_pretrained = caffe_pb2.NetParameter() |
| 34 | with open('data/testdata/caffe_translator/deploy.prototxt') as f: |
| 35 | text_format.Merge(f.read(), caffenet) |
| 36 | with open('data/testdata/caffe_translator/' |
| 37 | 'bvlc_reference_caffenet.caffemodel') as f: |
| 38 | caffenet_pretrained.ParseFromString(f.read()) |
| 39 | for remove_legacy_pad in [True, False]: |
| 40 | net, pretrained_params = caffe_translator.TranslateModel( |
| 41 | caffenet, caffenet_pretrained, is_test=True, |
| 42 | remove_legacy_pad=remove_legacy_pad |
| 43 | ) |
| 44 | with open('data/testdata/caffe_translator/' |
| 45 | 'bvlc_reference_caffenet.translatedmodel', |
| 46 | 'w') as fid: |
| 47 | fid.write(str(net)) |
| 48 | for param in pretrained_params.protos: |
| 49 | workspace.FeedBlob(param.name, utils.Caffe2TensorToNumpyArray(param)) |
| 50 | # Let's also feed in the data from the Caffe test code. |
| 51 | data = np.load('data/testdata/caffe_translator/data_dump.npy').astype( |
| 52 | np.float32) |
| 53 | workspace.FeedBlob('data', data) |
| 54 | # Actually running the test. |
| 55 | workspace.RunNetOnce(net.SerializeToString()) |
| 56 | |
| 57 | |
| 58 | @unittest.skipIf(not CAFFE_FOUND, |
nothing calls this directly
no test coverage detected
searching dependent graphs…