File size: 1,104 Bytes
aef7d7f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5107c4c
aef7d7f
 
 
 
f0542d9
aef7d7f
 
 
 
 
659a4c2
aef7d7f
 
 
 
5107c4c
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
def get_set_up():
    import torch
    TORCH_VERSION = ".".join(torch.__version__.split(".")[:2])
    CUDA_VERSION = torch.__version__.split("+")[-1]
    print("torch: ", TORCH_VERSION, "; cuda: ", CUDA_VERSION)
    print(f'GPU available: {torch.cuda.is_available()}')
    print(torch.cuda.get_device_capability())

    # print("detectron2:", detectron2.__version__)

def load_model():
    # def predictor(img):
    #     return {}
    # return predictor
    # import some common detectron2 utilities
    import torch
    from detectron2 import model_zoo
    from detectron2.engine import DefaultPredictor
    from detectron2.config import get_cfg
    from detectron2.data.datasets import register_coco_instances

    import os
    import numpy as np

    ## define relevant parameters
    cfg = get_cfg()
    cfg.merge_from_file("./configs/test_model_config.yaml")
    if not torch.cuda.is_available():
        cfg.MODEL.DEVICE = "cpu"
    else:
        cfg.MODEL.DEVICE = 'cuda'
    predictor = DefaultPredictor(cfg)

    return predictor

if __name__ == '__main__':
    # get_set_up()
    load_model()