Skip to content

Commit

Permalink
Save the planet by not reading images for size (#372)
Browse files Browse the repository at this point in the history
Summary:
```
In [7]: %timeit Image.open("datasets/coco/train2017/000000000009.jpg").size
34.9 µs ± 59.6 ns per loop (mean ± std. dev. of 7 runs, 10000 loops each)

In [8]: %timeit imagesize.get("datasets/coco/train2017/000000000009.jpg")
9.43 µs ± 64.2 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)
```

https://images.app.goo.gl/Msptv7xcCVsXJ5zh8
Pull Request resolved: facebookresearch/detectron2#372

Differential Revision: D18709576

Pulled By: ppwwyyxx

fbshipit-source-id: f6910eff7abafcda053a1e8ee33a370fc96aed20
  • Loading branch information
botcs authored and facebook-github-bot committed Nov 27, 2019
1 parent 4a0407d commit 38fedca
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
6 changes: 3 additions & 3 deletions detectron2/data/datasets/coco.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import datetime
import json
import numpy as np
import imagesize

from PIL import Image

Expand Down Expand Up @@ -262,12 +263,11 @@ def file2id(folder_path, file_path):

dataset_dicts = []
for (img_path, gt_path) in zip(input_files, gt_files):
local_path = PathManager.get_local_path(gt_path)
w, h = imagesize.get(local_path)
record = {}
record["file_name"] = img_path
record["sem_seg_file_name"] = gt_path
with PathManager.open(gt_path, "rb") as f:
img = Image.open(f)
w, h = img.size
record["height"] = h
record["width"] = w
dataset_dicts.append(record)
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ def get_model_zoo_configs() -> List[str]:
"matplotlib",
"tqdm>4.29.0",
"tensorboard",
"imagesize",
],
extras_require={"all": ["shapely", "psutil"]},
ext_modules=get_extensions(),
Expand Down

0 comments on commit 38fedca

Please sign in to comment.