Skip to content

Commit ccaf692

Browse files
committed
pano data form
1 parent 015c946 commit ccaf692

File tree

12 files changed

+1468
-467
lines changed

12 files changed

+1468
-467
lines changed
+127
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
AUTO_RESUME: true
2+
CUDNN:
3+
BENCHMARK: true
4+
DETERMINISTIC: false
5+
ENABLED: true
6+
DATA_DIR: ''
7+
GPUS: (0,)
8+
OUTPUT_DIR: 'output'
9+
LOG_DIR: 'log'
10+
WORKERS: 4
11+
PRINT_FREQ: 100
12+
13+
DATASET:
14+
COLOR_RGB: true
15+
DATASET: 'pano'
16+
DATA_FORMAT: jpg
17+
FLIP: false
18+
NUM_JOINTS_HALF_BODY: 0
19+
PROB_HALF_BODY: 0.0
20+
ROOT: 'data/pano/'
21+
ROT_FACTOR: 0
22+
SCALE_FACTOR: 0.0
23+
TEST_SET: 'test'
24+
TRAIN_SET: 'train'
25+
MODEL:
26+
INIT_WEIGHTS: true
27+
NAME: pose_hrnet
28+
NUM_JOINTS: 32
29+
PRETRAINED: ''
30+
TARGET_TYPE: gaussian
31+
IMAGE_SIZE:
32+
- 512
33+
- 256
34+
HEATMAP_SIZE:
35+
- 128
36+
- 64
37+
SIGMA: 1
38+
EXTRA:
39+
PRETRAINED_LAYERS:
40+
- 'conv1'
41+
- 'bn1'
42+
- 'conv2'
43+
- 'bn2'
44+
- 'layer1'
45+
- 'transition1'
46+
- 'stage2'
47+
- 'transition2'
48+
- 'stage3'
49+
- 'transition3'
50+
- 'stage4'
51+
FINAL_CONV_KERNEL: 1
52+
STAGE2:
53+
NUM_MODULES: 1
54+
NUM_BRANCHES: 2
55+
BLOCK: BASIC
56+
NUM_BLOCKS:
57+
- 4
58+
- 4
59+
NUM_CHANNELS:
60+
- 32
61+
- 64
62+
FUSE_METHOD: SUM
63+
STAGE3:
64+
NUM_MODULES: 4
65+
NUM_BRANCHES: 3
66+
BLOCK: BASIC
67+
NUM_BLOCKS:
68+
- 4
69+
- 4
70+
- 4
71+
NUM_CHANNELS:
72+
- 32
73+
- 64
74+
- 128
75+
FUSE_METHOD: SUM
76+
STAGE4:
77+
NUM_MODULES: 3
78+
NUM_BRANCHES: 4
79+
BLOCK: BASIC
80+
NUM_BLOCKS:
81+
- 4
82+
- 4
83+
- 4
84+
- 4
85+
NUM_CHANNELS:
86+
- 32
87+
- 64
88+
- 128
89+
- 256
90+
FUSE_METHOD: SUM
91+
LOSS:
92+
USE_TARGET_WEIGHT: true
93+
TRAIN:
94+
BATCH_SIZE_PER_GPU: 16
95+
SHUFFLE: true
96+
BEGIN_EPOCH: 0
97+
END_EPOCH: 210
98+
OPTIMIZER: adam
99+
LR: 0.001
100+
LR_FACTOR: 0.1
101+
LR_STEP:
102+
- 170
103+
- 200
104+
WD: 0.0001
105+
GAMMA1: 0.99
106+
GAMMA2: 0.0
107+
MOMENTUM: 0.9
108+
NESTEROV: false
109+
TEST:
110+
BATCH_SIZE_PER_GPU: 1
111+
COCO_BBOX_FILE: 'data/coco/person_detection_results/COCO_val2017_detections_AP_H_56_person.json'
112+
BBOX_THRE: 1.0
113+
IMAGE_THRE: 0.0
114+
IN_VIS_THRE: 0.2
115+
MODEL_FILE: ''
116+
NMS_THRE: 1.0
117+
OKS_THRE: 0.9
118+
USE_GT_BBOX: false
119+
FLIP_TEST: false
120+
POST_PROCESS: true
121+
SHIFT_HEATMAP: true
122+
DEBUG:
123+
DEBUG: true
124+
SAVE_BATCH_IMAGES_GT: true
125+
SAVE_BATCH_IMAGES_PRED: true
126+
SAVE_HEATMAPS_GT: true
127+
SAVE_HEATMAPS_PRED: true

lib/core/function.py

+99-38
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from core.evaluate import accuracy
1919
from core.inference import get_final_preds
2020
from utils.transforms import flip_back
21-
from utils.vis import save_debug_images
21+
from utils.vis import save_result_images, save_debug_images
2222

2323

2424
logger = logging.getLogger(__name__)
@@ -194,47 +194,108 @@ def validate(config, val_loader, val_dataset, model, criterion, output_dir,
194194
save_debug_images(config, input, meta, target, pred*4, output,
195195
prefix)
196196

197-
name_values, perf_indicator = val_dataset.evaluate(
198-
config, all_preds, output_dir, all_boxes, image_path,
199-
filenames, imgnums
200-
)
197+
return 0
201198

202-
model_name = config.MODEL.NAME
203-
if isinstance(name_values, list):
204-
for name_value in name_values:
205-
_print_name_value(name_value, model_name)
206-
else:
207-
_print_name_value(name_values, model_name)
199+
def test(config, val_loader, val_dataset, model, criterion, output_dir,
200+
tb_log_dir, writer_dict=None):
201+
batch_time = AverageMeter()
202+
losses = AverageMeter()
203+
acc = AverageMeter()
208204

209-
if writer_dict:
210-
writer = writer_dict['writer']
211-
global_steps = writer_dict['valid_global_steps']
212-
writer.add_scalar(
213-
'valid_loss',
214-
losses.avg,
215-
global_steps
216-
)
217-
writer.add_scalar(
218-
'valid_acc',
219-
acc.avg,
220-
global_steps
221-
)
222-
if isinstance(name_values, list):
223-
for name_value in name_values:
224-
writer.add_scalars(
225-
'valid',
226-
dict(name_value),
227-
global_steps
228-
)
205+
# switch to evaluate mode
206+
model.eval()
207+
208+
num_samples = len(val_dataset)
209+
all_preds = np.zeros(
210+
(num_samples, config.MODEL.NUM_JOINTS, 3),
211+
dtype=np.float32
212+
)
213+
all_boxes = np.zeros((num_samples, 6))
214+
image_path = []
215+
filenames = []
216+
imgnums = []
217+
idx = 0
218+
with torch.no_grad():
219+
end = time.time()
220+
for i, (input, target, target_weight, meta) in enumerate(val_loader):
221+
# compute output
222+
outputs = model(input)
223+
if isinstance(outputs, list):
224+
output = outputs[-1]
229225
else:
230-
writer.add_scalars(
231-
'valid',
232-
dict(name_values),
233-
global_steps
234-
)
235-
writer_dict['valid_global_steps'] = global_steps + 1
226+
output = outputs
227+
228+
if config.TEST.FLIP_TEST:
229+
input_flipped = input.flip(3)
230+
outputs_flipped = model(input_flipped)
231+
232+
if isinstance(outputs_flipped, list):
233+
output_flipped = outputs_flipped[-1]
234+
else:
235+
output_flipped = outputs_flipped
236+
237+
output_flipped = flip_back(output_flipped.cpu().numpy(),
238+
val_dataset.flip_pairs)
239+
output_flipped = torch.from_numpy(output_flipped.copy()).cuda()
240+
241+
242+
# feature is not aligned, shift flipped heatmap for higher accuracy
243+
if config.TEST.SHIFT_HEATMAP:
244+
output_flipped[:, :, :, 1:] = \
245+
output_flipped.clone()[:, :, :, 0:-1]
246+
247+
output = (output + output_flipped) * 0.5
248+
249+
target = target.cuda(non_blocking=True)
250+
target_weight = target_weight.cuda(non_blocking=True)
251+
252+
loss = criterion(output, target, target_weight)
253+
254+
num_images = input.size(0)
255+
# measure accuracy and record loss
256+
losses.update(loss.item(), num_images)
257+
_, avg_acc, cnt, pred = accuracy(output.cpu().numpy(),
258+
target.cpu().numpy())
259+
260+
acc.update(avg_acc, cnt)
261+
262+
# measure elapsed time
263+
batch_time.update(time.time() - end)
264+
end = time.time()
265+
266+
c = meta['center'].numpy()
267+
s = meta['scale'].numpy()
268+
score = meta['score'].numpy()
269+
270+
preds, maxvals = get_final_preds(
271+
config, output.clone().cpu().numpy(), c, s)
272+
273+
all_preds[idx:idx + num_images, :, 0:2] = preds[:, :, 0:2]
274+
all_preds[idx:idx + num_images, :, 2:3] = maxvals
275+
# double check this all_boxes parts
276+
all_boxes[idx:idx + num_images, 0:2] = c[:, 0:2]
277+
all_boxes[idx:idx + num_images, 2:4] = s[:, 0:2]
278+
all_boxes[idx:idx + num_images, 4] = np.prod(s*200, 1)
279+
all_boxes[idx:idx + num_images, 5] = score
280+
image_path.extend(meta['image'])
281+
282+
idx += num_images
283+
284+
if i % 1 == 0:
285+
msg = 'Test: [{0}/{1}]\t' \
286+
'Time {batch_time.val:.3f} ({batch_time.avg:.3f})\t' \
287+
'Loss {loss.val:.4f} ({loss.avg:.4f})\t' \
288+
'Accuracy {acc.val:.3f} ({acc.avg:.3f})'.format(
289+
i, len(val_loader), batch_time=batch_time,
290+
loss=losses, acc=acc)
291+
logger.info(msg)
292+
293+
prefix = os.path.join(output_dir, 'result')
294+
295+
save_result_images(config, input, meta, target, pred*4, output,
296+
prefix, i)
236297

237-
return perf_indicator
298+
return 0
238299

239300

240301
# markdown format output

0 commit comments

Comments
 (0)