-
Notifications
You must be signed in to change notification settings - Fork 16
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
Alexandre Boulch
committed
Oct 17, 2017
1 parent
82c9b0a
commit 940845f
Showing
6 changed files
with
682 additions
and
2 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,23 @@ | ||
|
||
# License information | ||
|
||
The code is released under a dual license depending on applications, research or commercial. | ||
|
||
--- | ||
|
||
## COMMERCIAL PURPOSES | ||
|
||
Please contact the ONERA [www.onera.fr/en/contact-us](www.onera.fr/en/contact-us) for additional information. | ||
|
||
--- | ||
|
||
## RESEARCH AND NON COMMERCIAL PURPOSES | ||
|
||
#### Code license | ||
|
||
For research and non commercial purposes, all the code and documentation of github.com/aboulch/snapnet is released under the GPLv3 license: | ||
|
||
DeLTA Toolbox, a toolbox for ONERA DeLTA project | ||
Copyright (C) 2017 ONERA, Alexandre Boulch | ||
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or any later version. | ||
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
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 |
---|---|---|
@@ -1,2 +1,9 @@ | ||
# delta_tb | ||
Toolbox for the ONERA Delta project | ||
# Toolbox for DeLTA project | ||
|
||
Toolbox for the [ONERA Delta project](https://delta-onera.github.io). | ||
|
||
This toolbox provides code sample developped in the project for various applications. It will be enriched as the project goes on. | ||
|
||
## [Semantic segmentation](semantic_segmentation/semantic_segmentation.md) | ||
|
||
## [License](LICENSE) |
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,107 @@ | ||
"""Image Folder Data loader""" | ||
|
||
import torch.utils.data as data | ||
import torchvision.transforms as transforms | ||
import numpy as np | ||
from PIL import Image, ImageMath, ImageOps | ||
import os | ||
import os.path | ||
import random | ||
|
||
|
||
def make_dataset(input_dir, target_dir, filenames): | ||
"""Create the dataset.""" | ||
images = [] | ||
# deal with multiple input | ||
|
||
text_file = open(filenames, 'r') | ||
lines = text_file.readlines() | ||
|
||
for filename in lines: | ||
filename = filename.split("\n")[0] | ||
item = [] | ||
item.append(os.path.join(input_dir, filename)) | ||
|
||
if target_dir is not None: | ||
item.append(os.path.join(target_dir, filename)) | ||
else: | ||
item.append(None) | ||
|
||
images.append(item) | ||
|
||
return images | ||
|
||
|
||
def pil_loader(path): | ||
"""Load PIL images.""" | ||
return Image.open(path) | ||
|
||
|
||
def default_loader(path): | ||
"""Load Default loader.""" | ||
return pil_loader(path) | ||
|
||
|
||
class ImageFolderDenseFileLists(data.Dataset): | ||
"""Main Class for Image Folder loader.""" | ||
|
||
def __init__(self, input_root, | ||
target_root=None, | ||
filenames=None, loader=default_loader, | ||
training=True, mirror=True): | ||
"""Init function.""" | ||
# | ||
# get the lists of images | ||
imgs = make_dataset(input_root, target_root, filenames, extensions) | ||
|
||
if len(imgs) == 0: | ||
raise(RuntimeError("Found 0 images in subfolders of: " + input_root + "\n" | ||
"Supported image extensions are: " + ",".join(IMG_EXTENSIONS))) | ||
|
||
self.input_root = input_root | ||
self.target_root = target_root | ||
self.imgs = imgs | ||
|
||
|
||
self.loader = loader | ||
self.training = training | ||
|
||
self.mirror = mirror | ||
|
||
def __getitem__(self, index): | ||
"""Get item.""" | ||
|
||
input_paths = self.imgs[index][0] | ||
target_path = self.imgs[index][1] | ||
|
||
input_img = self.loader(p) | ||
|
||
# random flip | ||
if self.mirror: | ||
use_mirror = random.randint(0,1) | ||
if(use_mirror): | ||
input_img = ImageOps.mirror(input_img) | ||
|
||
# apply transformation | ||
input_img = self.transform(input_img) | ||
transform = transforms.Compose([transforms.ToTensor()]) | ||
input_img = transform(input_img) | ||
|
||
if self.training: | ||
target_img = self.loader(target_path) | ||
if(use_mirror): | ||
target_img = ImageOps.mirror(target_img) | ||
target_img = transform(target_img) | ||
else: | ||
target_img = np.array([index]) # index of the image in the filelist | ||
target_img = np.array(target_img) | ||
|
||
return input_img, target_img | ||
|
||
def __len__(self): | ||
"""Length.""" | ||
return len(self.imgs) | ||
|
||
def get_filename(self, id): | ||
"""Get the filename.""" | ||
return self.imgs[id] |
Oops, something went wrong.