"git@developer.sourcefind.cn:Wenxuan/LightX2V.git" did not exist on "a8fdaaee357aba2d2000fe7cea1ccc5faeefbf6d"
Commit d6a966fd authored by Shiyu Dong's avatar Shiyu Dong Committed by Facebook GitHub Bot
Browse files

Add CallFuncWithNameAndJsonFile

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

Add a new call function to handle adhoc datasets that needs to be called with dataset_name. This is mainly to handle the incompatibility of `extend_coco_load` function with AdhocDataset

For example,
* if we choose to register `extend_coco_load` function as CallFuncWithJsonFile, AdhocDataset will register the same function, while failed to update the `dataset_name` argument passed to `extended_coco_load`.

* If we choose to register `extend_coco_load` function normally, we couldn't use the `LOAD_KWARGS` that specifies additional fields like `image_direct_copy_keys` when register AdhocDatasets

Therefore adding the new function allows to update register function with specifying new json as well as new dataset_name in the same time.

Reviewed By: sstsai-adl

Differential Revision: D37100742

fbshipit-source-id: 93f4a7ac23f95812aca80c40872b15f92d449da0
parent 7e436109
......@@ -101,6 +101,20 @@ class CallFuncWithJsonFile(object):
return self.func(self.json_file)
class CallFuncWithNameAndJsonFile(object):
"""
Same purpose as CallFuncWithJsonFile but also pass name to `func` as arguments
"""
def __init__(self, func, json_file, name):
self.func = func
self.name = name
self.json_file = json_file
def __call__(self):
return self.func(self.json_file, self.name)
class AdhocCOCODataset(AdhocDataset):
def __init__(self, src_ds_name, new_ds_name):
super().__init__(new_ds_name)
......@@ -145,6 +159,11 @@ class AdhocCOCODataset(AdhocDataset):
if isinstance(load_func, CallFuncWithJsonFile):
new_func = CallFuncWithJsonFile(func=load_func.func, json_file=tmp_file)
DatasetCatalog.register(self.new_ds_name, new_func)
elif isinstance(load_func, CallFuncWithNameAndJsonFile):
new_func = CallFuncWithNameAndJsonFile(
func=load_func.func, name=self.new_ds_name, json_file=tmp_file
)
DatasetCatalog.register(self.new_ds_name, new_func)
elif self.src_ds_name in INJECTED_COCO_DATASETS_LUT:
_src_func, _src_dict = INJECTED_COCO_DATASETS_LUT[self.src_ds_name]
_src_func(
......
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