Commit b117baf1 authored by Yanghan Wang's avatar Yanghan Wang Committed by Facebook GitHub Bot
Browse files

add __init__ to d2go.quantization

Summary:
Pull Request resolved: https://github.com/facebookresearch/d2go/pull/228

This diff solves https://github.com/facebookresearch/d2go/issues/226

Reviewed By: tglik

Differential Revision: D36026321

fbshipit-source-id: 216b0bf7bc48c45deb093c238d70de2b40bc37a3
parent ae269bce
......@@ -38,7 +38,7 @@ def create_test_images_and_dataset_json(data_dir, num_images=10, num_classes=-1)
num_images=num_images,
num_classes=num_classes,
)
json_file = os.path.join(data_dir, "{}.json".format("inj_ds1"))
json_file = os.path.join(data_dir, "annotation.json")
with open(json_file, "w") as f:
json.dump(json_dataset, f)
......@@ -46,6 +46,16 @@ def create_test_images_and_dataset_json(data_dir, num_images=10, num_classes=-1)
class TestD2GoDatasets(unittest.TestCase):
def setUp(self):
self._builtin_datasets = set(DatasetCatalog)
def tearDown(self):
# Need to remove injected dataset
injected_dataset = set(DatasetCatalog) - self._builtin_datasets
for ds in injected_dataset:
DatasetCatalog.remove(ds)
MetadataCatalog.remove(ds)
def test_coco_conversions(self):
test_data_0 = {
"info": {},
......
......@@ -13,7 +13,6 @@ from d2go.export.api import (
FuncInfo,
PredictorExportConfig,
)
from d2go.export.fb.caffe2 import DefaultCaffe2Export
from d2go.export.torchscript import (
DefaultTorchscriptExport,
TracingAdaptedTorchscriptExport,
......@@ -220,17 +219,31 @@ class MultiDictInMultiDictOut(nn.Module):
torch.testing.assert_allclose(second["sub"], torch.tensor([-2]))
class TestModelExportMethods(unittest.TestCase):
@parameterized.expand(
[
MODEL_EXPORT_METHOD_TEST_CASES = [
[DefaultTorchscriptExport, MultiTensorInSingleTensorOut],
[DefaultTorchscriptExport, SingleListInSingleListOut],
# [DefaultCaffe2Export, MultiTensorInSingleTensorOut], # TODO: make caffe2 support this
[DefaultCaffe2Export, SingleListInSingleListOut],
[TracingAdaptedTorchscriptExport, MultiTensorInSingleTensorOut],
[TracingAdaptedTorchscriptExport, SingleListInSingleListOut],
[TracingAdaptedTorchscriptExport, MultiDictInMultiDictOut],
],
]
try:
from d2go.export.fb.caffe2 import DefaultCaffe2Export
MODEL_EXPORT_METHOD_TEST_CASES.extend(
[
# [DefaultCaffe2Export, MultiTensorInSingleTensorOut], # TODO: make caffe2 support this
[DefaultCaffe2Export, SingleListInSingleListOut],
]
)
except ImportError:
pass
class TestModelExportMethods(unittest.TestCase):
@parameterized.expand(
MODEL_EXPORT_METHOD_TEST_CASES,
name_func=lambda testcase_func, param_num, param: (
"{}_{}_{}".format(
testcase_func.__name__, param.args[0].__name__, param.args[1].__name__
......
#!/usr/bin/env python3
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
import glob
import os
import unittest
import pkg_resources
class TestSubPackageInitFile(unittest.TestCase):
def test_has_init_files(self):
"""We require every subpackage has an __init__.py file"""
root = pkg_resources.resource_filename("d2go", "")
all_py_files = glob.glob(f"{root}/**/*.py", recursive=True)
all_package_dirs = [os.path.dirname(f) for f in all_py_files]
all_package_dirs = sorted(set(all_package_dirs)) # dedup
init_files = [
os.path.join(os.path.relpath(d, root), "__init__.py")
for d in all_package_dirs
]
print("Checking following files ...\n{}".format("\n".join(init_files)))
missing_init_files = [
f for f in init_files if not os.path.isfile(os.path.join(root, f))
]
self.assertTrue(
len(missing_init_files) == 0,
"Missing following __init__.py files:\n{}".format(
"\n".join(missing_init_files)
),
)
......@@ -17,7 +17,7 @@ from d2go.utils.testing.data_loader_helper import (
)
from d2go.utils.testing.helper import tempdir
from d2go.utils.visualization import VisualizerWrapper, DataLoaderVisWrapper
from detectron2.data import DatasetCatalog
from detectron2.data import DatasetCatalog, MetadataCatalog
from detectron2.modeling import META_ARCH_REGISTRY
from detectron2.structures import Boxes, Instances
from detectron2.utils.events import EventStorage
......@@ -34,7 +34,7 @@ def create_test_images_and_dataset_json(
num_images=num_images,
num_classes=num_classes,
)
json_file = os.path.join(data_dir, "{}.json".format("inj_ds1"))
json_file = os.path.join(data_dir, "annotation.json")
with open(json_file, "w") as f:
json.dump(json_dataset, f)
......@@ -75,6 +75,16 @@ class MockTbxWriter:
class TestVisualization(unittest.TestCase):
def setUp(self):
self._builtin_datasets = set(DatasetCatalog)
def tearDown(self):
# Need to remove injected dataset
injected_dataset = set(DatasetCatalog) - self._builtin_datasets
for ds in injected_dataset:
DatasetCatalog.remove(ds)
MetadataCatalog.remove(ds)
@tempdir
def test_visualizer_wrapper(self, tmp_dir: str):
image_dir, json_file = create_test_images_and_dataset_json(tmp_dir, 60, 60)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment