souranil3d commited on
Commit
955f4a2
1 Parent(s): 8f2741c

Updating dependency

Browse files
Files changed (5) hide show
  1. .gitignore +1 -0
  2. Base-RCNN-FPN.yaml +42 -0
  3. app.py +10 -4
  4. config.yaml +22 -0
  5. requirements.txt +23 -2
.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ .idea/
Base-RCNN-FPN.yaml ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ MODEL:
2
+ META_ARCHITECTURE: "GeneralizedRCNN"
3
+ BACKBONE:
4
+ NAME: "build_resnet_fpn_backbone"
5
+ RESNETS:
6
+ OUT_FEATURES: ["res2", "res3", "res4", "res5"]
7
+ FPN:
8
+ IN_FEATURES: ["res2", "res3", "res4", "res5"]
9
+ ANCHOR_GENERATOR:
10
+ SIZES: [[32], [64], [128], [256], [512]] # One size for each in feature map
11
+ ASPECT_RATIOS: [[0.5, 1.0, 2.0]] # Three aspect ratios (same for all in feature maps)
12
+ RPN:
13
+ IN_FEATURES: ["p2", "p3", "p4", "p5", "p6"]
14
+ PRE_NMS_TOPK_TRAIN: 2000 # Per FPN level
15
+ PRE_NMS_TOPK_TEST: 1000 # Per FPN level
16
+ # Detectron1 uses 2000 proposals per-batch,
17
+ # (See "modeling/rpn/rpn_outputs.py" for details of this legacy issue)
18
+ # which is approximately 1000 proposals per-image since the default batch size for FPN is 2.
19
+ POST_NMS_TOPK_TRAIN: 1000
20
+ POST_NMS_TOPK_TEST: 1000
21
+ ROI_HEADS:
22
+ NAME: "StandardROIHeads"
23
+ IN_FEATURES: ["p2", "p3", "p4", "p5"]
24
+ ROI_BOX_HEAD:
25
+ NAME: "FastRCNNConvFCHead"
26
+ NUM_FC: 2
27
+ POOLER_RESOLUTION: 7
28
+ ROI_MASK_HEAD:
29
+ NAME: "MaskRCNNConvUpsampleHead"
30
+ NUM_CONV: 4
31
+ POOLER_RESOLUTION: 14
32
+ DATASETS:
33
+ TRAIN: ("coco_2017_train",)
34
+ TEST: ("coco_2017_val",)
35
+ SOLVER:
36
+ IMS_PER_BATCH: 16
37
+ BASE_LR: 0.02
38
+ STEPS: (60000, 80000)
39
+ MAX_ITER: 90000
40
+ INPUT:
41
+ MIN_SIZE_TRAIN: (640, 672, 704, 736, 768, 800)
42
+ VERSION: 2
app.py CHANGED
@@ -1,22 +1,28 @@
 
 
 
1
  import gradio as gr
2
  import logging
3
  from detectron2.engine import DefaultPredictor
4
  import cv2
5
  from detectron2.config import get_cfg
6
- from src.utils.visualizer import add_bboxes
 
 
 
7
 
8
  config_file="config.yaml"
9
  cfg = get_cfg()
10
  cfg.merge_from_file(config_file)
11
  cfg.MODEL.DEVICE="cpu"
12
  cfg.MODEL.ROI_HEADS.SCORE_THRESH_TEST = 0.5
13
- cfg.MODEL.WEIGHTS = "checkpoints_model_final_imagenet_40k_synthetic.pth.pth"
14
 
15
  def predict(
16
- config_file, checkpoint_file, img_path
17
  ):
18
  predictor = DefaultPredictor(cfg)
19
- im = cv2.imread(img_path)
20
  output = predictor(im)
21
  img = add_bboxes(im, output['instances'].pred_boxes, scores=output['instances'].scores)
22
  return img
 
1
+ import os
2
+ os.system('pip install git+https://github.com/facebookresearch/detectron2.git')
3
+
4
  import gradio as gr
5
  import logging
6
  from detectron2.engine import DefaultPredictor
7
  import cv2
8
  from detectron2.config import get_cfg
9
+ from utils import add_bboxes
10
+
11
+ # print(torch.__version__, torch.cuda.is_available())
12
+ # assert torch.__version__.startswith("1.9")
13
 
14
  config_file="config.yaml"
15
  cfg = get_cfg()
16
  cfg.merge_from_file(config_file)
17
  cfg.MODEL.DEVICE="cpu"
18
  cfg.MODEL.ROI_HEADS.SCORE_THRESH_TEST = 0.5
19
+ cfg.MODEL.WEIGHTS = "checkpoints_model_final_imagenet_40k_synthetic.pth"
20
 
21
  def predict(
22
+ img
23
  ):
24
  predictor = DefaultPredictor(cfg)
25
+ im = cv2.imread(img.name)
26
  output = predictor(im)
27
  img = add_bboxes(im, output['instances'].pred_boxes, scores=output['instances'].scores)
28
  return img
config.yaml ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ _BASE_: "./Base-RCNN-FPN.yaml"
2
+ MODEL:
3
+ WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-50.pkl"
4
+ MASK_ON: False
5
+ BACKBONE:
6
+ FREEZE_AT: 0
7
+ RESNETS:
8
+ DEPTH: 50
9
+ ROI_HEADS:
10
+ NUM_CLASSES: 1
11
+ SOLVER:
12
+ STEPS: (210000, 250000)
13
+ MAX_ITER: 270000
14
+ IMS_PER_BATCH: 1
15
+ BASE_LR: 0.00025
16
+ GAMMA: 0.1
17
+ REFERENCE_WORLD_SIZE: 1
18
+
19
+ DATALOADER:
20
+ NUM_WORKERS: 1
21
+
22
+
requirements.txt CHANGED
@@ -1,4 +1,25 @@
 
1
  torch==1.9.0
2
  torchvision==0.10.0
3
- git+https://github.com/facebookresearch/detectron2.git
4
- opencv-python
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ pyyaml==5.1
2
  torch==1.9.0
3
  torchvision==0.10.0
4
+
5
+ docutils==0.16
6
+ # https://github.com/sphinx-doc/sphinx/commit/7acd3ada3f38076af7b2b5c9f3b60bb9c2587a3d
7
+ sphinx==3.2.0
8
+ recommonmark==0.6.0
9
+ sphinx_rtd_theme
10
+ # Dependencies here are only those required by import
11
+ termcolor
12
+ numpy
13
+ tqdm
14
+ matplotlib
15
+ termcolor
16
+ yacs
17
+ tabulate
18
+ cloudpickle
19
+ Pillow
20
+ future
21
+ git+https://github.com/facebookresearch/fvcore
22
+ omegaconf>=2.1.0.dev24
23
+ hydra-core>=1.1.0.dev5
24
+
25
+ opencv-python-headless