Skip to content

Commit

Permalink
Addressing MR comments and updating readme
Browse files Browse the repository at this point in the history
  • Loading branch information
mdfirman committed May 18, 2021
1 parent 55870cb commit ea8feec
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
16 changes: 11 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This is the reference PyTorch implementation for training and testing depth esti

> **Digging into Self-Supervised Monocular Depth Prediction**
>
> [Clément Godard](http://www0.cs.ucl.ac.uk/staff/C.Godard/), [Oisin Mac Aodha](http://vision.caltech.edu/~macaodha/), [Michael Firman](http://www.michaelfirman.co.uk) and [Gabriel J. Brostow](http://www0.cs.ucl.ac.uk/staff/g.brostow/)
> [Clément Godard](http://www0.cs.ucl.ac.uk/staff/C.Godard/), [Oisin Mac Aodha](http://vision.caltech.edu/~macaodha/), [Michael Firman](http://www.michaelfirman.co.uk) and [Gabriel J. Brostow](http://www0.cs.ucl.ac.uk/staff/g.brostow/)
>
> [ICCV 2019 (arXiv pdf)](https://arxiv.org/abs/1806.01260)
Expand Down Expand Up @@ -49,14 +49,20 @@ We also recommend using `pillow-simd` instead of `pillow` for faster image prepr

## 🖼️ Prediction for a single image

You can predict depth for a single image with:
You can predict scaled disparity for a single image with:

```shell
python test_simple.py --image_path assets/test_image.jpg --model_name mono+stereo_640x192
```

On its first run this will download the `mono+stereo_640x192` pretrained model (99MB) into the `models/` folder.
We provide the following options for `--model_name`:
or, if you are using a stereo-trained model, you can estimate metric depth with

```shell
python test_simple.py --image_path assets/test_image.jpg --model_name mono+stereo_640x192 --pred_metric_depth
```

On its first run either of these commands will download the `mono+stereo_640x192` pretrained model (99MB) into the `models/` folder.
We provide the following options for `--model_name`:

| `--model_name` | Training modality | Imagenet pretrained? | Model resolution | KITTI abs. rel. error | delta < 1.25 |
|-------------------------|-------------------|--------------------------|-----------------|------|----------------|
Expand All @@ -72,7 +78,7 @@ We provide the following options for `--model_name`:

You can also download models trained on the odometry split with [monocular](https://storage.googleapis.com/niantic-lon-static/research/monodepth2/mono_odom_640x192.zip) and [mono+stereo](https://storage.googleapis.com/niantic-lon-static/research/monodepth2/mono%2Bstereo_odom_640x192.zip) training modalities.

Finally, we provide resnet 50 depth estimation models trained with [ImageNet pretrained weights](https://storage.googleapis.com/niantic-lon-static/research/monodepth2/mono_resnet50_640x192.zip) and [trained from scratch](https://storage.googleapis.com/niantic-lon-static/research/monodepth2/mono_resnet50_no_pt_640x192.zip).
Finally, we provide resnet 50 depth estimation models trained with [ImageNet pretrained weights](https://storage.googleapis.com/niantic-lon-static/research/monodepth2/mono_resnet50_640x192.zip) and [trained from scratch](https://storage.googleapis.com/niantic-lon-static/research/monodepth2/mono_resnet50_no_pt_640x192.zip).
Make sure to set `--num_layers 50` if using these.

## 💾 KITTI training data
Expand Down
15 changes: 8 additions & 7 deletions test_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ def parse_args():
parser.add_argument("--no_cuda",
help='if set, disables CUDA',
action='store_true')
parser.add_argument("--pred_depth",
parser.add_argument("--pred_metric_depth",
help='if set, predicts metric depth instead of disparity. (This only '
'makes sense for stereo-trained models).',
'makes sense for stereo-trained KITTI models).',
action='store_true')

return parser.parse_args()
Expand All @@ -66,9 +66,9 @@ def test_simple(args):
else:
device = torch.device("cpu")

if args.pred_depth and "stereo" not in args.model_name:
print("Warning: The --pred_depth flag only makes sense for stereo-trained models. "
"For mono-trained models, output depths will not in metric space.")
if args.pred_metric_depth and "stereo" not in args.model_name:
print("Warning: The --pred_metric_depth flag only makes sense for stereo-trained KITTI "
"models. For mono-trained models, output depths will not in metric space.")

download_model_if_doesnt_exist(args.model_name)
model_path = os.path.join("models", args.model_name)
Expand Down Expand Up @@ -139,9 +139,10 @@ def test_simple(args):
# Saving numpy file
output_name = os.path.splitext(os.path.basename(image_path))[0]
scaled_disp, depth = disp_to_depth(disp, 0.1, 100)
if args.pred_depth:
if args.pred_metric_depth:
name_dest_npy = os.path.join(output_directory, "{}_depth.npy".format(output_name))
np.save(name_dest_npy, STEREO_SCALE_FACTOR * depth.cpu().numpy())
metric_depth = STEREO_SCALE_FACTOR * depth.cpu().numpy()
np.save(name_dest_npy, metric_depth)
else:
name_dest_npy = os.path.join(output_directory, "{}_disp.npy".format(output_name))
np.save(name_dest_npy, scaled_disp.cpu().numpy())
Expand Down

0 comments on commit ea8feec

Please sign in to comment.