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

easier way to separate internal code from oss

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

Reviewed By: zhanghang1989

Differential Revision: D29279123

fbshipit-source-id: d94cea65bd439d54fd14afded0dba066799cedca
parent bc9d5070
#!/usr/bin/env python3
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
import d2go.data.datasets
......@@ -7,8 +7,8 @@ import importlib
import logging
import os
from d2go.data.fb.adhoc_hive_dataset import COCOHiveLoaderConfig
from d2go.utils.helper import get_dir_path
from d2go.utils.misc import fb_overwritable
from detectron2.data import DatasetCatalog, MetadataCatalog
from .extended_coco import coco_text_load, extended_coco_load
......@@ -48,11 +48,16 @@ def _register_extended_coco(dataset_name, split_dict):
meta_data = split_dict.get("meta_data", {})
MetadataCatalog.get(dataset_name).set(
evaluator_type=evaluator_type,
auto_hive_loader_config=COCOHiveLoaderConfig,
json_file=json_file,
image_root=image_root,
**meta_data
**meta_data,
)
_add_additional_extended_coco_metadata(dataset_name)
@fb_overwritable()
def _add_additional_extended_coco_metadata(dataset_name):
pass
def _register_extended_lvis(dataset_name, split_dict):
......
#!/usr/bin/env python3
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
from d2go.utils.misc import fb_overwritable
@fb_overwritable()
def get_launch_environment():
return "local"
......@@ -12,6 +12,7 @@ import detectron2.utils.comm as comm
import torch
from d2go.config import CfgNode
from detectron2.utils.file_io import PathManager
from mobile_cv.common.misc.py import dynamic_import
from tabulate import tabulate
from .tensorboard_log_util import get_tensorboard_log_dir # noqa: forwarding
......@@ -104,9 +105,31 @@ def mode(net: torch.nn.Module, training: bool) -> Iterator[torch.nn.Module]:
finally:
net.train(istrain)
def _log_api_usage(identifier: str):
"""
Internal function used to log the usage of different d2go components
inside facebook's infra.
"""
torch._C._log_api_usage_once("d2go." + identifier)
def fb_overwritable():
"""Decorator on function that has alternative internal implementation"""
try:
import d2go.infra.fb # NOQA
is_oss = False
except ImportError:
is_oss = True
def deco(oss_func):
if is_oss:
return oss_func
else:
oss_module = oss_func.__module__
fb_module = oss_module + "_fb" # xxx.py -> xxx_fb.py
fb_func = dynamic_import("{}.{}".format(fb_module, oss_func.__name__))
return fb_func
return deco
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