|
7 | 7 | import torch
|
8 | 8 | import unittest
|
9 | 9 |
|
10 |
| -from caffe2.python import core, dyndep, workspace |
| 10 | +from caffe2.python import core, workspace |
11 | 11 | from hypothesis import given, settings
|
12 | 12 | from scipy.stats import norm
|
13 | 13 |
|
14 |
| -dyndep.InitOpsLibrary('@/caffe2/caffe2/fb/operators:calibration_op') |
15 |
| - |
16 | 14 |
|
17 | 15 | def generate_rois(roi_counts, im_dims):
|
18 | 16 | assert len(roi_counts) == len(im_dims)
|
@@ -877,71 +875,6 @@ def _batch_bucket_one_hot_ref(data, lengths, boundaries):
|
877 | 875 | )
|
878 | 876 | torch.testing.assert_allclose(expected_output, actual_output.cpu())
|
879 | 877 |
|
880 |
| - def test_gather_ranges_to_dense_op(self): |
881 |
| - data = np.array([1, 2, 3, 4, 5, 6, 7, 8]) |
882 |
| - ranges = np.array([[[2, 4]], [[0, 0]]]) |
883 |
| - key = np.array([0, 1, 3, 2, 1, 0, 1, 0]) |
884 |
| - lengths = np.array([4]) |
885 |
| - min_observation = 2 |
886 |
| - max_mismatched_ratio = 0.5 |
887 |
| - max_empty_ratio = 1.0 |
888 |
| - |
889 |
| - outputs_name = ["X_{}".format(i) for i in range(len(lengths))] |
890 |
| - ref_op = core.CreateOperator( |
891 |
| - "GatherRangesToDense", |
892 |
| - ["data", "ranges", "key"], |
893 |
| - outputs_name, |
894 |
| - lengths=lengths, |
895 |
| - min_observation=min_observation, |
896 |
| - max_mismatched_ratio=max_mismatched_ratio, |
897 |
| - max_empty_ratio=max_empty_ratio, |
898 |
| - ) |
899 |
| - workspace.FeedBlob("data", data) |
900 |
| - workspace.FeedBlob("ranges", ranges) |
901 |
| - workspace.FeedBlob("key", key) |
902 |
| - workspace.RunOperatorOnce(ref_op) |
903 |
| - ref_outputs = [] |
904 |
| - for output_name in outputs_name: |
905 |
| - ref_outputs.append(workspace.FetchBlob(output_name)) |
906 |
| - |
907 |
| - outputs = torch.ops._caffe2.GatherRangesToDense( |
908 |
| - torch.from_numpy(data), |
909 |
| - torch.from_numpy(ranges), |
910 |
| - torch.from_numpy(key), |
911 |
| - lengths=lengths, |
912 |
| - min_observation=min_observation, |
913 |
| - max_mismatched_ratio=max_mismatched_ratio, |
914 |
| - max_empty_ratio=max_empty_ratio, |
915 |
| - ) |
916 |
| - |
917 |
| - self.assertEqual(len(ref_outputs), len(outputs)) |
918 |
| - for i in range(0, len(ref_outputs)): |
919 |
| - np.testing.assert_array_almost_equal(ref_outputs[i], outputs[i].numpy()) |
920 |
| - |
921 |
| - def test_prior_correct_calibration_prediction_op(self): |
922 |
| - beta = np.array([1.0, 2.0], dtype=np.float32) |
923 |
| - gamma = np.array([3.0, 4.0], dtype=np.float32) |
924 |
| - pred = np.array([0.1, 0.2, 0.3, 0.4], dtype=np.float32) |
925 |
| - |
926 |
| - ref_op = core.CreateOperator( |
927 |
| - "PriorCorrectionCalibrationPrediction", |
928 |
| - ["beta", "gamma", "pred"], |
929 |
| - ["new_pred"], |
930 |
| - ) |
931 |
| - workspace.FeedBlob("beta", beta) |
932 |
| - workspace.FeedBlob("gamma", gamma) |
933 |
| - workspace.FeedBlob("pred", pred) |
934 |
| - workspace.RunOperatorOnce(ref_op) |
935 |
| - ref_output = workspace.FetchBlob("new_pred") |
936 |
| - |
937 |
| - output = torch.ops._caffe2.PriorCorrectionCalibrationPrediction( |
938 |
| - torch.from_numpy(beta), |
939 |
| - torch.from_numpy(gamma), |
940 |
| - torch.from_numpy(pred), |
941 |
| - ) |
942 |
| - torch.testing.assert_allclose(ref_output, output) |
943 |
| - |
944 |
| - |
945 | 878 | @given(lengths_0=st.integers(1, 10), lengths_1=st.integers(1, 10))
|
946 | 879 | @settings(deadline=1000)
|
947 | 880 | def test_merge_id_lists(self, lengths_0, lengths_1):
|
|
0 commit comments