Skip to content

Commit 5853034

Browse files
committed
update mscoco support. add annotations json file (see readme)
1 parent 37b4a25 commit 5853034

File tree

9 files changed

+152
-134
lines changed

9 files changed

+152
-134
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ test_transforms.py
1111
experiments
1212
run
1313
data/mscoco/coco
14-
data/mscoco/keypoint
14+
data/mscoco/annotations
15+
data/mscoco/images
1516
*.m~
1617
miscs/posetrack
1718
miscs/h36m

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ PyTorch-Pose is a PyTorch implementation of the general pipeline for 2D single h
44

55
Some codes for data preparation and augmentation are brought from the [Stacked hourglass network](https://github.com/anewell/pose-hg-train). Thanks to the original author.
66

7-
**Update: this repository is compatible with PyTorch 1.0 now!**
7+
**Update: this repository is compatible with PyTorch 0.4.1/1.0 now!**
88

99
## Features
1010
- Multi-thread data loading
@@ -13,7 +13,7 @@ Some codes for data preparation and augmentation are brought from the [Stacked h
1313
- Training/testing results visualization
1414

1515
## Installation
16-
1. PyTorch (>= 0.4.0): Please follow the [installation instruction of PyTorch](http://pytorch.org/). Note that the code is developed with Python2 and has not been tested with Python3 yet.
16+
1. PyTorch (>= 0.4.1): Please follow the [installation instruction of PyTorch](http://pytorch.org/). Note that the code is developed with Python2 and has not been tested with Python3 yet.
1717

1818
2. Clone the repository with submodule
1919
```
@@ -24,12 +24,17 @@ Some codes for data preparation and augmentation are brought from the [Stacked h
2424
```
2525
ln -s PATH_TO_MPII_IMAGES_DIR data/mpii/images
2626
```
27+
For training/testing on COCO, please refer to [COCO Readme](https://github.com/bearpaw/pytorch-pose/blob/master/data/mscoco/README.md).
2728

2829
4. Modify your `.bashrc` file:
2930
```
3031
export PYTHONPATH=".:$PYTHONPATH"
3132
```
3233

34+
5. Download annotation file:
35+
* (MPII) Download [mpii_annotations.json](https://drive.google.com/open?id=1mQrH_yVHeB93rzCfyq5kC9ZYTwZeMsMm) and save it to `data/mpii`
36+
* (MSCOCO) Download [coco_annotations_2014.json](https://drive.google.com/open?id=1jrxis4ujrLlkwoD2GOdv3PGzygpQ04k7) or/and [coco_annotations_2017.json](https://drive.google.com/open?id=1YuzpScAfzemwZqUuZBrbBZdoplXEqUse) and save it to `data/mscoco`
37+
3338
## Usage
3439

3540
### Testing

data/lsp/images/lsp_dataset

Lines changed: 0 additions & 1 deletion
This file was deleted.

data/lsp/images/lspet_dataset

Lines changed: 0 additions & 1 deletion
This file was deleted.

data/mscoco/README.md

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,22 @@
11
## Directory structure
2+
To train on coco (single person pose estimation), place the following files in the right place.
23

3-
- `coco`: [coco API](https://github.com/pdollar/coco)
4-
- `keypoint`: COCO keypoint dataset
5-
- `images`: tain and val datasets
6-
- `train2014`
7-
- `val2014`
8-
- `person_keypoints_train+val5k2014`: annotations (JSON files)
9-
- `coco_annotations.json`: reformatted annotation generated by `./miscs/gen_coco.m`
4+
- `cocoapi`: [coco API](https://github.com/cocodataset/cocoapi)
5+
- `annotations`: COCO keypoint dataset
6+
- `person_keypoints_train+val5k2014`: annotations (JSON files)
7+
- `images`: tain and val datasets
8+
- `train2014`
9+
- `val2014`
10+
- `coco_annotations_2014.json` or `coco_annotations_2014.json`: reformatted annotation generated by `./miscs/gen_coco.m`
11+
12+
### Prepare `json` annotation file
13+
Please edit `year = 2017; % 2014 or 2017 ` in [gen_coco.m](https://github.com/bearpaw/pytorch-pose/blob/master/miscs/gen_coco.m) to generate the corresponding annotation file (coco2014 or coco2017).
14+
15+
### Training recipes
16+
17+
```
18+
CUDA_VISIBLE_DEVICES=1 python example/mscoco.py \
19+
--checkpoint checkpoint/mscoco/hg-s1-b1 \
20+
-s 1 \
21+
-b 1
22+
```

example/lsp.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def main(args):
4646
# define loss function (criterion) and optimizer
4747
criterion = torch.nn.MSELoss(size_average=True).cuda()
4848

49-
optimizer = torch.optim.RMSprop(model.parameters(),
49+
optimizer = torch.optim.RMSprop(model.parameters(),
5050
lr=args.lr,
5151
momentum=args.momentum,
5252
weight_decay=args.weight_decay)
@@ -66,7 +66,7 @@ def main(args):
6666
logger = Logger(join(args.checkpoint, 'log.txt'), title=title, resume=True)
6767
else:
6868
print("=> no checkpoint found at '{}'".format(args.resume))
69-
else:
69+
else:
7070
logger = Logger(join(args.checkpoint, 'log.txt'), title=title)
7171
logger.set_names(['Epoch', 'LR', 'Train Loss', 'Val Loss', 'Train Acc', 'Val Acc'])
7272

@@ -79,15 +79,15 @@ def main(args):
7979
sigma=args.sigma, label_type=args.label_type),
8080
batch_size=args.train_batch, shuffle=True,
8181
num_workers=args.workers, pin_memory=True)
82-
82+
8383
val_loader = torch.utils.data.DataLoader(
8484
datasets.LSP('data/lsp/LEEDS_annotations.json', 'data/lsp/images',
8585
sigma=args.sigma, label_type=args.label_type, train=False),
8686
batch_size=args.test_batch, shuffle=False,
8787
num_workers=args.workers, pin_memory=True)
8888

8989
if args.evaluate:
90-
print('\nEvaluation only')
90+
print('\nEvaluation only')
9191
loss, acc, predictions = validate(val_loader, model, criterion, args.num_classes, args.debug, args.flip)
9292
save_pred(predictions, checkpoint=args.checkpoint)
9393
return
@@ -174,7 +174,7 @@ def train(train_loader, model, criterion, optimizer, debug=False, flip=True):
174174
plt.draw()
175175

176176
# measure accuracy and record loss
177-
losses.update(loss.data[0], inputs.size(0))
177+
losses.update(loss.item(), inputs.size(0))
178178
acces.update(acc[0], inputs.size(0))
179179

180180
# compute gradient and do SGD step
@@ -232,7 +232,7 @@ def validate(val_loader, model, criterion, num_classes, debug=False, flip=True):
232232
score_map = output[-1].data.cpu()
233233
if flip:
234234
flip_input_var = torch.autograd.Variable(
235-
torch.from_numpy(fliplr(inputs.clone().numpy())).float().cuda(),
235+
torch.from_numpy(fliplr(inputs.clone().numpy())).float().cuda(),
236236
volatile=True
237237
)
238238
flip_output_var = model(flip_input_var)
@@ -267,7 +267,7 @@ def validate(val_loader, model, criterion, num_classes, debug=False, flip=True):
267267
plt.draw()
268268

269269
# measure accuracy and record loss
270-
losses.update(loss.data[0], inputs.size(0))
270+
losses.update(loss.item(), inputs.size(0))
271271
acces.update(acc[0], inputs.size(0))
272272

273273
# measure elapsed time
@@ -348,4 +348,4 @@ def validate(val_loader, model, criterion, num_classes, debug=False, flip=True):
348348
help='show intermediate results')
349349

350350

351-
main(parser.parse_args())
351+
main(parser.parse_args())

example/mpii.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def main(args):
124124
'state_dict': model.state_dict(),
125125
'best_acc': best_acc,
126126
'optimizer' : optimizer.state_dict(),
127-
}, predictions, is_best, checkpoint=args.checkpoint)
127+
}, predictions, is_best, checkpoint=args.checkpoint, snapshot=args.snapshot)
128128

129129
logger.close()
130130
logger.plot(['Train Acc', 'Val Acc'])
@@ -229,13 +229,10 @@ def validate(val_loader, model, criterion, num_classes, debug=False, flip=True):
229229
target = target.to(device, non_blocking=True)
230230

231231
# compute output
232-
output = model(input)
232+
output = model(input)[-1]
233233
score_map = output[-1].cpu()
234234
if flip:
235-
flip_input = torch.autograd.Variable(
236-
torch.from_numpy(fliplr(input.clone().numpy())).float().to(device),
237-
volatile=True
238-
)
235+
flip_input = torch.from_numpy(fliplr(input.clone().numpy())).float().to(device)
239236
flip_output_var = model(flip_input)
240237
flip_output = flip_back(flip_output_var[-1].cpu())
241238
score_map += flip_output

0 commit comments

Comments
 (0)