1+ from fvcore .common .file_io import PathHandler , PathManager , HTTPURLHandler
2+
3+ MODEL_CATALOG = {
4+ 'HJDataset' : {
5+ 'faster_rcnn_R_50_FPN_3x' : 'https://www.dropbox.com/s/6icw6at8m28a2ho/model_final.pth?dl=1' ,
6+ 'mask_rcnn_R_50_FPN_3x' : 'https://www.dropbox.com/s/893paxpy5suvlx9/model_final.pth?dl=1' ,
7+ 'retinanet_R_50_FPN_3x' : 'https://www.dropbox.com/s/yxsloxu3djt456i/model_final.pth?dl=1'
8+ }
9+ }
10+
11+ CONFIG_CATALOG = {
12+ 'HJDataset' : {
13+ 'faster_rcnn_R_50_FPN_3x' : 'https://www.dropbox.com/s/j4yseny2u0hn22r/config.yml?dl=1' ,
14+ 'mask_rcnn_R_50_FPN_3x' : 'https://www.dropbox.com/s/4jmr3xanmxmjcf8/config.yml?dl=0' ,
15+ 'retinanet_R_50_FPN_3x' : 'https://www.dropbox.com/s/z8a8ywozuyc5c2x/config.yml?dl=0'
16+ }
17+ }
18+
19+ class DropboxHandler (HTTPURLHandler ):
20+ """
21+ Supports download and file check for dropbox links
22+ """
23+ def _get_supported_prefixes (self ):
24+ return ["https://www.dropbox.com" ]
25+
26+ def _isfile (self , path ):
27+ return path in self .cache_map
28+
29+
30+ class LayoutParserHandler (PathHandler ):
31+ """
32+ Resolve anything that's in LayoutParser model zoo.
33+ """
34+
35+ PREFIX = "lp://"
36+
37+ def _get_supported_prefixes (self ):
38+ return [self .PREFIX ]
39+
40+ def _get_local_path (self , path ):
41+ model_name = path [len (self .PREFIX ):]
42+ dataset_name , * model_name , data_type = model_name .split ('/' )
43+
44+ if data_type == 'weight' :
45+ model_url = MODEL_CATALOG [dataset_name ]['/' .join (model_name )]
46+ elif data_type == 'config' :
47+ model_url = CONFIG_CATALOG [dataset_name ]['/' .join (model_name )]
48+ else :
49+ raise ValueError (f"Unknown data_type { data_type } " )
50+ return PathManager .get_local_path (model_url )
51+
52+ def _open (self , path , mode = "r" , ** kwargs ):
53+ return PathManager .open (self ._get_local_path (path ), mode , ** kwargs )
54+
55+
56+ PathManager .register_handler (DropboxHandler ())
57+ PathManager .register_handler (LayoutParserHandler ())
0 commit comments