Skip to content

Commit 7079faf

Browse files
committed
v1_stable
0 parents  commit 7079faf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+39175
-0
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
logs/
2+
weights/
3+
**/.idea
4+
**/__pycache__
5+
.ignore
6+
run/

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Config Base pytorch FrameWork
2+
3+
This Framework

clean_log_folder.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import os
2+
import shutil
3+
4+
5+
def delete_empty_logs():
6+
for root, d_names, f_names in os.walk('./logs'):
7+
if os.path.basename(root) == 'weights':
8+
if len(f_names) <= 1:
9+
shutil.rmtree(root)
10+
print(f_names)
11+
12+
for root, d_names, f_names in os.walk('./logs'):
13+
if os.path.basename(root) != 'weights':
14+
if len(f_names) > 1 and not ('weights' in d_names):
15+
shutil.rmtree(root)
16+
print(root)
17+
18+
for root, d_names, f_names in os.walk('./logs', topdown=False):
19+
if len(d_names) == 0 and len(f_names) == 0:
20+
shutil.rmtree(root)
21+
22+
23+
if __name__ == "__main__":
24+
print('hi')
25+
delete_empty_logs()
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
TRAIN:
2+
INPUT_SIZE: None
3+
BATCH_SIZE: 4
4+
EPOCHS: 20
5+
STEP: 'FasterRCNN-mobilenet_v3_large_320_fpn'
6+
PARAM:
7+
OPTIMIZER: 'SGD'
8+
OPTIMIZER_PARAM:
9+
lr: 0.005
10+
momentum: 0.9
11+
weight_decay: 0.0005
12+
13+
MODEL:
14+
NAME: 'fasterrcnn_mobilenet_v3_large_320_fpn'
15+
PARAM:
16+
pretrained: false
17+
progress: false,
18+
num_classes: 3,
19+
pretrained_backbone: true,
20+
trainable_backbone_layers: null
21+
# resnet50_fpn, mobilenet_v3_large_fpn, mobilenet_v3_large_320_fpn,
22+
23+
DATASET:
24+
NAME: 'AFCID'
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
TRAIN:
2+
INPUT_SIZE: None
3+
BATCH_SIZE: 4
4+
EPOCHS: 20
5+
STEP: 'FasterRCNN-mobilenet_v3_large_fpn'
6+
PARAM:
7+
OPTIMIZER: 'SGD'
8+
OPTIMIZER_PARAM:
9+
lr: 0.005
10+
momentum: 0.9
11+
weight_decay: 0.0005
12+
13+
MODEL:
14+
NAME: 'fasterrcnn_mobilenet_v3_large_fpn'
15+
PARAM:
16+
pretrained: false
17+
progress: false,
18+
num_classes: 3,
19+
pretrained_backbone: true,
20+
trainable_backbone_layers: null
21+
# resnet50_fpn, mobilenet_v3_large_fpn, mobilenet_v3_large_320_fpn,
22+
23+
DATASET:
24+
NAME: 'AFCID'
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
TRAIN:
2+
INPUT_SIZE: None
3+
BATCH_SIZE: 4
4+
EPOCHS: 20
5+
STEP: 'FasterRCNN-resnet50_fpn'
6+
PARAM:
7+
OPTIMIZER: 'SGD'
8+
OPTIMIZER_PARAM:
9+
lr: 0.005
10+
momentum: 0.9
11+
weight_decay: 0.0005
12+
13+
MODEL:
14+
NAME: 'fasterrcnn_resnet50_fpn'
15+
PARAM:
16+
pretrained: false
17+
progress: false,
18+
num_classes: 3,
19+
pretrained_backbone: true,
20+
trainable_backbone_layers: null
21+
# resnet50_fpn, mobilenet_v3_large_fpn, mobilenet_v3_large_320_fpn,
22+
23+
DATASET:
24+
NAME: 'AFCID'
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
TRAIN:
2+
INPUT_SIZE: None
3+
BATCH_SIZE: 4
4+
EPOCHS: 20
5+
STEP: 'RetinaNet_resnet50_fpn'
6+
PARAM:
7+
OPTIMIZER: 'SGD'
8+
OPTIMIZER_PARAM:
9+
lr: 0.005
10+
momentum: 0.9
11+
weight_decay: 0.0005
12+
13+
MODEL:
14+
NAME: 'retinanet_resnet50_fpn'
15+
PARAM:
16+
pretrained: false
17+
progress: false,
18+
num_classes: 3,
19+
pretrained_backbone: true,
20+
trainable_backbone_layers: null
21+
22+
DATASET:
23+
NAME: 'AFCID'

config/capsulorhexis/SSD300_vgg16.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
TRAIN:
2+
INPUT_SIZE: None
3+
BATCH_SIZE: 4
4+
EPOCHS: 20
5+
STEP: 'SSD300_vgg16'
6+
PARAM:
7+
OPTIMIZER: 'SGD'
8+
OPTIMIZER_PARAM:
9+
lr: 0.005
10+
momentum: 0.9
11+
weight_decay: 0.0005
12+
13+
MODEL:
14+
NAME: 'ssd300_vgg16'
15+
PARAM:
16+
pretrained: false
17+
progress: false,
18+
num_classes: 3,
19+
pretrained_backbone: true,
20+
trainable_backbone_layers: null
21+
22+
DATASET:
23+
NAME: 'AFCID'
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
TRAIN:
2+
INPUT_SIZE: None
3+
BATCH_SIZE: 4
4+
EPOCHS: 20
5+
STEP: 'SSDlite320_mobilenet_v3_large'
6+
PARAM:
7+
OPTIMIZER: 'SGD'
8+
OPTIMIZER_PARAM:
9+
lr: 0.005
10+
momentum: 0.9
11+
weight_decay: 0.0005
12+
13+
MODEL:
14+
NAME: 'ssdlite320_mobilenet_v3_large'
15+
PARAM:
16+
pretrained: false
17+
progress: false,
18+
num_classes: 3,
19+
pretrained_backbone: true,
20+
trainable_backbone_layers: null
21+
22+
DATASET:
23+
NAME: 'AFCID'

config/system/Colab.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
SYSTEM:
2+
NUM_GPUS: 2
3+
NUM_WORKERS: 4
4+
DEVISE: 'cuda'
5+
CUDA_VISIBLE_DEVICES: "'0'"
6+
MAX_BATCH_SIZE: 10
7+
DATASET:
8+
PATH: '../'
9+
LOGGING:
10+
BEST: true
11+
COMMENT: 'just flip augment'

core/config.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
from yacs.config import CfgNode as CN
2+
3+
_C = CN()
4+
5+
_C.LOGGING = CN()
6+
_C.LOGGING.HOST = ''
7+
_C.LOGGING.TIME = ''
8+
_C.LOGGING.WEIGHT_FOLDER = './'
9+
_C.LOGGING.LOG_DIR = './'
10+
_C.LOGGING.COMMENT = ''
11+
_C.LOGGING.BEST = False
12+
13+
_C.SYSTEM = CN()
14+
_C.SYSTEM.NUM_GPUS = 1
15+
_C.SYSTEM.NUM_WORKERS = 4
16+
_C.SYSTEM.DEVISE = 'cuda'
17+
_C.SYSTEM.CUDA_VISIBLE_DEVICES = '0,2,3,4,5,6,7,8'
18+
_C.SYSTEM.MAX_BATCH_SIZE = 16
19+
20+
_C.MODEL = CN(new_allowed=True)
21+
_C.MODEL.NAME = 'NAN'
22+
# _C.MODEL.G1 = CN()
23+
# _C.MODEL.G1.BACKBONE = 'Unet'
24+
# _C.MODEL.G1.USE_DISCRIMINATOR = False
25+
# _C.MODEL.G1.HEAD = False
26+
# _C.MODEL.G1.HEAD_PARAM = CN(new_allowed=True)
27+
# _C.MODEL.G1.BACKBONE_PARAM = CN(new_allowed=True)
28+
# _C.MODEL.G2 = CN()
29+
# _C.MODEL.G2.BACKBONE = 'Unet'
30+
# _C.MODEL.G2.USE_DISCRIMINATOR = False
31+
# _C.MODEL.G2.HEAD = False
32+
# _C.MODEL.G2.HEAD_PARAM = CN(new_allowed=True)
33+
# _C.MODEL.G2.BACKBONE_PARAM = CN(new_allowed=True)
34+
# _C.MODEL.G3 = CN()
35+
# _C.MODEL.G3.BACKBONE = 'Unet'
36+
# _C.MODEL.G3.USE_DISCRIMINATOR = False
37+
# _C.MODEL.G3.BACKBONE_PARAM = CN(new_allowed=True)
38+
# _C.MODEL.G3.HEAD = 'CoordPlusNum'
39+
# _C.MODEL.G3.HEAD_PARAM = CN(new_allowed=True)
40+
41+
_C.TRAIN = CN()
42+
_C.TRAIN.INPUT_SIZE = (512, 512)
43+
_C.TRAIN.BATCH_SIZE = 10
44+
_C.TRAIN.EPOCHS = 50
45+
_C.TRAIN.STEP = 'e2e' # options ['S1', 'S2', 'S3', 'e2e']
46+
_C.TRAIN.PARAM = CN(new_allowed=True)
47+
# _C.TRAIN.G1 = CN(new_allowed=True)
48+
# _C.TRAIN.G1.OPTIMIZER = 'Adam'
49+
# _C.TRAIN.G1.OPTIMIZER_PARAM = CN(new_allowed=True)
50+
# _C.TRAIN.G1.LOSS = 'SmoothL1Loss'
51+
# _C.TRAIN.G1.LOSS_PARAM = CN(new_allowed=True)
52+
#
53+
# _C.TRAIN.G2 = CN(new_allowed=True)
54+
# _C.TRAIN.G2.OPTIMIZER = 'Adam'
55+
# _C.TRAIN.G2.OPTIMIZER_PARAM = CN(new_allowed=True)
56+
# _C.TRAIN.G2.LOSS = 'SmoothL1Loss'
57+
# _C.TRAIN.G2.LOSS_PARAM = CN(new_allowed=True)
58+
#
59+
# _C.TRAIN.G3 = CN(new_allowed=True)
60+
# _C.TRAIN.G3.OPTIMIZER = 'Adam'
61+
# _C.TRAIN.G3.OPTIMIZER_PARAM = CN(new_allowed=True)
62+
# _C.TRAIN.G3.LOSS = 'SmoothL1Loss'
63+
# _C.TRAIN.G3.LOSS_PARAM = CN(new_allowed=True)
64+
65+
_C.DATASET = CN()
66+
_C.DATASET.NAME = 'CIHP'
67+
_C.DATASET.PATH = './dataset'
68+
69+
cfg = _C

infrence_SR.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import time
2+
from torch.utils.data import DataLoader
3+
from lib.data.datasets import *
4+
from lib.core import *
5+
6+
from lib.utils.environment import init_env
7+
8+
from core.config import cfg
9+
import lib.engine.detection.utils as utils
10+
import lib.engine.detection.transforms as T
11+
12+
13+
def get_transform():
14+
transforms = [T.ToTensor()]
15+
return T.Compose(transforms)
16+
17+
18+
if __name__ == '__main__':
19+
device, writer = init_env(cfg, has_writer=True)
20+
# get the model
21+
model = eval("{}".format(cfg.MODEL.NAME))(cfg.MODEL.PARAM)
22+
# move model to the right device
23+
model.to(device)
24+
25+
DATASET_PATH = cfg.DATASET.PATH
26+
test_ds = eval(cfg.DATASET.NAME)(DATASET_PATH, train='test', transforms=get_transform())
27+
28+
NUM_WORKERS = cfg.SYSTEM.NUM_WORKERS
29+
test_dl = torch.utils.data.DataLoader(
30+
test_ds, batch_size=1, shuffle=False, num_workers=NUM_WORKERS,
31+
collate_fn=utils.collate_fn)
32+
33+
print("number of test samples :{}".format(len(test_ds)))
34+
print("number of train batch :{}".format(len(test_dl)))
35+
36+
model.eval()
37+
sum_time = 0
38+
t = tqdm(test_dl, desc='calculating inference time..')
39+
40+
for image, _ in t:
41+
image = list(img.to(device) for img in image)
42+
st = time.time()
43+
outputs = model(image)
44+
sum_time += (time.time() - st)
45+
print("mean fps:", 1/(sum_time/len(test_dl)))
46+
print("mean inference time:", sum_time/len(test_dl))
47+
with open('inference_time.txt', 'a') as f:
48+
f.write("Model: {}\n".format(cfg.MODEL.NAME))
49+
f.write("mean fps: {}\n".format(1/(sum_time/len(test_dl))))
50+
f.write("mean inference time: {}\n".format(sum_time/len(test_dl)))
51+
f.write("*****************************************************\n")
52+
f.write("*****************************************************\n")
53+
f.write("*****************************************************\n")
54+

lib/__init__.py

Whitespace-only changes.

lib/backbone/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .unet import *

0 commit comments

Comments
 (0)