-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bb2f487
commit be4501c
Showing
55 changed files
with
3,675 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
data/ | ||
log/ | ||
log_old/ | ||
weights/ | ||
output/ | ||
visual/ | ||
.vscode | ||
|
||
# Mac directory meta file | ||
.DS_Store | ||
|
||
# intellij config | ||
.idea | ||
|
||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
wheels/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
MANIFEST | ||
|
||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
*.manifest | ||
*.spec | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
*.cover | ||
.hypothesis/ | ||
.pytest_cache/ | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
# Django stuff: | ||
*.log | ||
local_settings.py | ||
db.sqlite3 | ||
|
||
# Flask stuff: | ||
instance/ | ||
.webassets-cache | ||
|
||
# Scrapy stuff: | ||
.scrapy | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# PyBuilder | ||
target/ | ||
|
||
# Jupyter Notebook | ||
.ipynb_checkpoints | ||
|
||
# pyenv | ||
.python-version | ||
|
||
# celery beat schedule file | ||
celerybeat-schedule | ||
|
||
# SageMath parsed files | ||
*.sage.py | ||
|
||
# Environments | ||
.env | ||
.venv | ||
env/ | ||
venv/ | ||
ENV/ | ||
env.bak/ | ||
venv.bak/ | ||
|
||
# Spyder project settings | ||
.spyderproject | ||
.spyproject | ||
|
||
# Rope project settings | ||
.ropeproject | ||
|
||
# mkdocs documentation | ||
/site | ||
|
||
# mypy | ||
.mypy_cache/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2020 Ho Kei Cheng, Jihoon Chung | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from .online_dataset import OnlineTransformDataset | ||
from .offline_dataset import OfflineDataset | ||
from .split_dataset import SplitTransformDataset |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import numpy as np | ||
|
||
def is_bb_overlap(rmin, rmax, cmin, cmax, | ||
crmin, crmax, ccmin, ccmax): | ||
|
||
is_y_overlap = (rmax > crmin) and (crmax > rmin) | ||
is_x_overlap = (cmax > ccmin) and (ccmax > cmin) | ||
|
||
return is_x_overlap and is_y_overlap | ||
|
||
def get_bb_position(mask): | ||
mask = mask > 0.5 | ||
rows = np.any(mask, axis=1) | ||
cols = np.any(mask, axis=0) | ||
rmin, rmax = np.where(rows)[0][[0, -1]] | ||
cmin, cmax = np.where(cols)[0][[0, -1]] | ||
|
||
# y_min, y_max, x_min, x_max | ||
return rmin, rmax, cmin, cmax | ||
|
||
def scale_bb_by(rmin, rmax, cmin, cmax, im_height, im_width, h_scale, w_scale): | ||
height = rmax - rmin | ||
width = cmax - cmin | ||
|
||
rmin -= h_scale * height / 2 | ||
rmax += h_scale * height / 2 | ||
cmin -= w_scale * width / 2 | ||
cmax += w_scale * width / 2 | ||
|
||
rmin = int(max(0, rmin)) | ||
rmax = int(min(im_height-1, rmax)) | ||
cmin = int(max(0, cmin)) | ||
cmax = int(min(im_width-1, cmax)) | ||
|
||
# Prevent negative width/height | ||
rmax = max(rmin, rmax) | ||
cmax = max(cmin, cmax) | ||
|
||
return rmin, rmax, cmin, cmax |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
import os | ||
from os import path | ||
from torch.utils.data.dataset import Dataset | ||
from torchvision import transforms, utils | ||
from torchvision.transforms import functional | ||
from PIL import Image | ||
import numpy as np | ||
import progressbar | ||
|
||
from dataset.make_bb_trans import * | ||
|
||
class OfflineDataset(Dataset): | ||
def __init__(self, root, in_memory=False, need_name=False, resize=False, do_crop=False): | ||
self.root = root | ||
self.need_name = need_name | ||
self.resize = resize | ||
self.do_crop = do_crop | ||
self.in_memory = in_memory | ||
|
||
imgs = os.listdir(root) | ||
imgs = sorted(imgs) | ||
|
||
""" | ||
There are three kinds of files: _im.png, _seg.png, _gt.png | ||
""" | ||
im_list = [im for im in imgs if 'im' in im[-7:].lower()] | ||
|
||
self.im_list = [path.join(root, im) for im in im_list] | ||
|
||
print('%d images found' % len(self.im_list)) | ||
|
||
# Make up some transforms | ||
self.im_transform = transforms.Compose([ | ||
transforms.ToTensor(), | ||
transforms.Normalize( | ||
mean=[0.485, 0.456, 0.406], | ||
std=[0.229, 0.224, 0.225] | ||
), | ||
]) | ||
|
||
self.gt_transform = transforms.Compose([ | ||
transforms.ToTensor(), | ||
]) | ||
|
||
self.seg_transform = transforms.Compose([ | ||
transforms.ToTensor(), | ||
transforms.Normalize( | ||
mean=[0.5], | ||
std=[0.5] | ||
), | ||
]) | ||
|
||
if self.resize: | ||
self.resize_bi = lambda x: x.resize((224, 224), Image.BILINEAR) | ||
self.resize_nr = lambda x: x.resize((224, 224), Image.NEAREST) | ||
else: | ||
self.resize_bi = lambda x: x | ||
self.resize_nr = lambda x: x | ||
|
||
if self.in_memory: | ||
print('Loading things into memory') | ||
self.images = [] | ||
self.gts = [] | ||
self.segs = [] | ||
for im in progressbar.progressbar(self.im_list): | ||
image, seg, gt = self.load_tuple(im) | ||
|
||
self.images.append(image) | ||
self.segs.append(seg) | ||
self.gts.append(gt) | ||
|
||
def load_tuple(self, im): | ||
seg = Image.open(im[:-7]+'_seg.png').convert('L') | ||
crop_lambda = self.get_crop_lambda(seg) | ||
|
||
image = self.resize_bi(crop_lambda(Image.open(im).convert('RGB'))) | ||
gt = self.resize_bi(crop_lambda(Image.open(im[:-7]+'_gt.png').convert('L'))) | ||
seg = self.resize_bi(crop_lambda(Image.open(im[:-7]+'_seg.png').convert('L'))) | ||
|
||
return image, seg, gt | ||
|
||
def get_crop_lambda(self, seg): | ||
if self.do_crop: | ||
seg = np.array(seg) | ||
h, w = seg.shape | ||
try: | ||
bb = get_bb_position(seg) | ||
rmin, rmax, cmin, cmax = scale_bb_by(*bb, h, w, 0.15, 0.15) | ||
return lambda x: functional.crop(x, rmin, cmin, rmax-rmin, cmax-cmin) | ||
except: | ||
return lambda x: x | ||
else: | ||
return lambda x: x | ||
|
||
def __getitem__(self, idx): | ||
if self.in_memory: | ||
im = self.images[idx] | ||
gt = self.gts[idx] | ||
seg = self.segs[idx] | ||
else: | ||
im, seg, gt = self.load_tuple(self.im_list[idx]) | ||
|
||
im = self.im_transform(im) | ||
gt = self.gt_transform(gt) | ||
seg = self.seg_transform(seg) | ||
|
||
if self.need_name: | ||
return im, seg, gt, os.path.basename(self.im_list[idx][:-7]) | ||
else: | ||
return im, seg, gt | ||
|
||
def __len__(self): | ||
return len(self.im_list) | ||
|
||
if __name__ == '__main__': | ||
o = OfflineDataset('data/val_static') |
Oops, something went wrong.