-
Notifications
You must be signed in to change notification settings - Fork 7
/
_init_stuff.py
55 lines (48 loc) · 1.36 KB
/
_init_stuff.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
"""
Initialize stuff
"""
import pdb
from pathlib import Path
from typing import List, Dict, Any, Union
from yacs.config import CfgNode as CN
import numpy as np
import torch
from torch.utils.data import Dataset, DataLoader
import os
import sys
import yaml
import re
import pandas as pd
Fpath = Union[Path, str]
Cft = CN
Arr = Union[np.array, List, torch.tensor]
DF = pd.DataFrame
# Ds = Dataset
# This is required to read 5e-4 as a float rather than string
# at all places yaml should be imported from here
yaml.SafeLoader.add_implicit_resolver(
u'tag:yaml.org,2002:float',
re.compile(u'''^(?:
[-+]?(?:[0-9][0-9_]*)\\.[0-9_]*(?:[eE][-+]?[0-9]+)?
|[-+]?(?:[0-9][0-9_]*)(?:[eE][-+]?[0-9]+)
|\\.[0-9_]+(?:[eE][-+][0-9]+)?
|[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+\\.[0-9_]*
|[-+]?\\.(?:inf|Inf|INF)
|\\.(?:nan|NaN|NAN))$''', re.X),
list(u'-+0123456789.'))
# _SCRIPTPATH_ =
sys.path.append('./code/')
sys.path.append('./utils')
class ForkedPdb(pdb.Pdb):
"""A Pdb subclass that may be used
from a forked multiprocessing child
Credits:
https://github.com/williamFalcon/forked-pdb/blob/master/fpdb.py
"""
def interaction(self, *args, **kwargs):
_stdin = sys.stdin
try:
sys.stdin = open('/dev/stdin')
pdb.Pdb.interaction(self, *args, **kwargs)
finally:
sys.stdin = _stdin