Skip to content

Commit 1f320fc

Browse files
Added experiment config and dataset preparation script (#11)
* added shell scipt to prepare dataset * fixed path errors * added 1x and 3x experiment configs * fixed formatting
1 parent c2e12fe commit 1f320fc

File tree

4 files changed

+101
-58
lines changed

4 files changed

+101
-58
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/bin/bash
2+
3+
sudo apt update
4+
sudo apt install unzip aria2 -y
5+
6+
DATA_DIR=$1
7+
aria2c -j 8 -Z \
8+
http://images.cocodataset.org/annotations/annotations_trainval2017.zip \
9+
http://images.cocodataset.org/annotations/panoptic_annotations_trainval2017.zip \
10+
http://images.cocodataset.org/zips/train2017.zip \
11+
http://images.cocodataset.org/zips/val2017.zip \
12+
--dir=$DATA_DIR;
13+
14+
unzip $DATA_DIR/"*".zip -d $DATA_DIR;
15+
mkdir $DATA_DIR/zips && mv $DATA_DIR/*.zip $DATA_DIR/zips;
16+
unzip $DATA_DIR/annotations/panoptic_train2017.zip -d $DATA_DIR
17+
unzip $DATA_DIR/annotations/panoptic_val2017.zip -d $DATA_DIR
18+
19+
python3 official/vision/beta/data/create_coco_tf_record.py \
20+
--logtostderr \
21+
--image_dir="$DATA_DIR/val2017" \
22+
--object_annotations_file="$DATA_DIR/annotations/instances_val2017.json" \
23+
--output_file_prefix="$DATA_DIR/tfrecords/val" \
24+
--panoptic_annotations_file="$DATA_DIR/annotations/panoptic_val2017.json" \
25+
--panoptic_masks_dir="$DATA_DIR/panoptic_val2017" \
26+
--num_shards=8 \
27+
--include_masks \
28+
--include_panoptic_masks
29+
30+
31+
python3 official/vision/beta/data/create_coco_tf_record.py \
32+
--logtostderr \
33+
--image_dir="$DATA_DIR/train2017" \
34+
--object_annotations_file="$DATA_DIR/annotations/instances_train2017.json" \
35+
--output_file_prefix="$DATA_DIR/tfrecords/train" \
36+
--panoptic_annotations_file="$DATA_DIR/annotations/panoptic_train2017.json" \
37+
--panoptic_masks_dir="$DATA_DIR/panoptic_train2017" \
38+
--num_shards=32 \
39+
--include_masks \
40+
--include_panoptic_masks

official/vision/beta/projects/panoptic_maskrcnn/README.md

Lines changed: 11 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -20,58 +20,12 @@ prerequisites.
2020
$ git clone https://github.com/tensorflow/models.git
2121
$ cd models
2222
$ pip3 install -r official/requirements.txt
23+
$ export PYTHONPATH=$(pwd)
2324
```
2425

2526
## Preparing Dataset
26-
### Download and extract COCO dataset
2727
```bash
28-
$ sudo apt update
29-
$ sudo apt install unzip aria2 -y
30-
31-
$ export DATA_DIR=<path-to-store-tfrecords>
32-
$ aria2c -j 8 -Z \
33-
http://images.cocodataset.org/annotations/annotations_trainval2017.zip \
34-
http://images.cocodataset.org/annotations/panoptic_annotations_trainval2017.zip \
35-
http://images.cocodataset.org/zips/train2017.zip \
36-
http://images.cocodataset.org/zips/val2017.zip \
37-
--dir=$DATA_DIR;
38-
39-
$ unzip $DATA_DIR/"*".zip -d $DATA_DIR;
40-
$ mkdir $DATA_DIR/zips && mv $DATA_DIR/*.zip $DATA_DIR/zips;
41-
$ unzip $DATA_DIR/annotations/panoptic_train2017.zip -d $DATA_DIR
42-
$ unzip $DATA_DIR/annotations/panoptic_val2017.zip -d $DATA_DIR
43-
```
44-
45-
### Create TFrecords
46-
```bash
47-
$ cd official/vision/beta/data
48-
49-
$ python3 create_coco_tf_record.py \
50-
--logtostderr \
51-
--image_dir="$DATA_DIR/val2017" \
52-
--object_annotations_file="$DATA_DIR/annotations/instances_val2017.json" \
53-
--output_file_prefix="$DATA_DIR/tfrecords/val" \
54-
--panoptic_annotations_file="$DATA_DIR/annotations/panoptic_val2017.json" \
55-
--panoptic_masks_dir="$DATA_DIR/panoptic_val2017" \
56-
--num_shards=8 \
57-
--include_masks \
58-
--include_panoptic_masks
59-
60-
61-
$ python3 create_coco_tf_record.py \
62-
--logtostderr \
63-
--image_dir="$DATA_DIR/train2017" \
64-
--object_annotations_file="$DATA_DIR/annotations/instances_train2017.json" \
65-
--output_file_prefix="$DATA_DIR/tfrecords/train" \
66-
--panoptic_annotations_file="$DATA_DIR/annotations/panoptic_train2017.json" \
67-
--panoptic_masks_dir="$DATA_DIR/panoptic_train2017" \
68-
--num_shards=32 \
69-
--include_masks \
70-
--include_panoptic_masks
71-
```
72-
### Upload tfrecords to a Google Cloud Storage Bucket
73-
```bash
74-
$ gsutil -m cp -r "$DATA_DIR/tfrecords" gs://<bucket-details>
28+
$ ./official/vision/beta/data/process_coco_panoptic.sh <path-to-data-directory>
7529
```
7630

7731
## Launch Training
@@ -82,9 +36,9 @@ $ export ANNOTATION_FILE="gs://<path-to-coco-annotation-json>"
8236
$ export TRAIN_DATA="gs://<path-to-train-data>"
8337
$ export EVAL_DATA="gs://<path-to-eval-data>"
8438
$ export OVERRIDES="task.validation_data.input_path=${EVAL_DATA},\
85-
task.train_data.input_path=${TRAIN_DATA},\
86-
task.annotation_file=${ANNOTATION_FILE},\
87-
runtime.distribution_strategy=tpu"
39+
task.train_data.input_path=${TRAIN_DATA},\
40+
task.annotation_file=${ANNOTATION_FILE},\
41+
runtime.distribution_strategy=tpu"
8842

8943

9044
$ python3 train.py \
@@ -104,11 +58,11 @@ $ export ANNOTATION_FILE="gs://<path-to-coco-annotation-json>"
10458
$ export TRAIN_DATA="gs://<path-to-train-data>"
10559
$ export EVAL_DATA="gs://<path-to-eval-data>"
10660
$ export OVERRIDES="task.validation_data.input_path=${EVAL_DATA}, \
107-
task.train_data.input_path=${TRAIN_DATA}, \
108-
task.annotation_file=${ANNOTATION_FILE}, \
109-
runtime.distribution_strategy=mirrored, \
110-
runtime.mixed_precision_dtype=$PRECISION, \
111-
runtime.num_gpus=$NUM_GPUS"
61+
task.train_data.input_path=${TRAIN_DATA}, \
62+
task.annotation_file=${ANNOTATION_FILE}, \
63+
runtime.distribution_strategy=mirrored, \
64+
runtime.mixed_precision_dtype=$PRECISION, \
65+
runtime.num_gpus=$NUM_GPUS"
11266

11367

11468
$ python3 train.py \
@@ -117,7 +71,7 @@ $ python3 train.py \
11771
--model_dir $MODEL_DIR \
11872
--params_override=$OVERRIDES
11973
```
120-
**Note**: The [PanopticSegmentationGenerator](https://github.com/tensorflow/models/blob/ac7f9e7f2d0508913947242bad3e23ef7cae5a43/official/vision/beta/projects/panoptic_maskrcnn/modeling/layers/panoptic_segmentation_generator.py#L22) layer uses dynamic shapes and hence generating panoptic masks is not supported on Cloud TPUs. Running evaluation on Cloud TPUs is not supported for the same reson.
74+
**Note**: The [PanopticSegmentationGenerator](https://github.com/tensorflow/models/blob/ac7f9e7f2d0508913947242bad3e23ef7cae5a43/official/vision/beta/projects/panoptic_maskrcnn/modeling/layers/panoptic_segmentation_generator.py#L22) layer uses dynamic shapes and hence generating panoptic masks is not supported on Cloud TPUs. Running evaluation on Cloud TPUs is not supported for the same reason. However, training is both supported on Cloud TPUs and GPUs.
12175
## Pretrained Models
12276
Backbone | Schedule | Experiment name | Box mAP | Mask mAP | Overall PQ | Things PQ | Stuff PQ | Checkpoints
12377
:------------| :----------- | :---------------------------| ------- | ---------- | ---------- | --------- | -------- | ------------:
@@ -128,7 +82,6 @@ ResNet-50 | 3x | `panoptic_fpn_coco` | 40.64 | 36.29
12882

12983
___
13084
## Citation
131-
13285
```
13386
@misc{kirillov2019panoptic,
13487
title={Panoptic Feature Pyramid Networks},
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
runtime:
2+
distribution_strategy: 'tpu'
3+
mixed_precision_dtype: 'bfloat16'
4+
5+
task:
6+
init_checkpoint: 'gs://cloud-tpu-checkpoints/vision-2.0/resnet50_imagenet/ckpt-28080'
7+
annotation_file: 'coco/instances_val2017.json'
8+
train_data:
9+
global_batch_size: 64
10+
validation_data:
11+
global_batch_size: 8
12+
13+
trainer:
14+
train_steps: 22500
15+
optimizer_config:
16+
learning_rate:
17+
type: 'stepwise'
18+
stepwise:
19+
boundaries: [15000, 20000]
20+
values: [0.12, 0.012, 0.0012]
21+
warmup:
22+
type: 'linear'
23+
linear:
24+
warmup_steps: 500
25+
warmup_learning_rate: 0.0067
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
runtime:
2+
distribution_strategy: 'tpu'
3+
mixed_precision_dtype: 'bfloat16'
4+
5+
task:
6+
init_checkpoint: 'gs://cloud-tpu-checkpoints/vision-2.0/resnet50_imagenet/ckpt-28080'
7+
annotation_file: 'coco/instances_val2017.json'
8+
train_data:
9+
global_batch_size: 64
10+
validation_data:
11+
global_batch_size: 8
12+
13+
trainer:
14+
train_steps: 67500
15+
optimizer_config:
16+
learning_rate:
17+
type: 'stepwise'
18+
stepwise:
19+
boundaries: [45000, 60000]
20+
values: [0.12, 0.012, 0.0012]
21+
warmup:
22+
type: 'linear'
23+
linear:
24+
warmup_steps: 500
25+
warmup_learning_rate: 0.0067

0 commit comments

Comments
 (0)