This repository has been archived by the owner on Feb 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
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
Showing
8 changed files
with
150 additions
and
14 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 +1,2 @@ | ||
from .generator import Generator | ||
from .residual_model import residual_model |
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,52 @@ | ||
import numpy as np | ||
from cv2 import imread | ||
import os | ||
from keras.utils import Sequence | ||
|
||
|
||
class Generator(Sequence): | ||
"""Generates data for Keras""" | ||
|
||
def __init__(self, dataset_dir, batch_size=16, dim=(1920, 1080), n_channels=3, shuffle=True): | ||
"""Initialization""" | ||
data_folder = dataset_dir + "/data" | ||
self.data_paths = os.listdir(data_folder) | ||
|
||
labels_path = dataset_dir + "/masks" | ||
self.labels_paths = os.listdir(labels_path) | ||
|
||
self.batch_size = batch_size | ||
self.dim = dim | ||
self.n_channels = n_channels | ||
|
||
self.shuffle = shuffle | ||
|
||
self.len = len(self.data_paths) | ||
|
||
def __len__(self): | ||
"""Denotes the number of batches per epoch | ||
:return: number of batches per epoch | ||
""" | ||
return len(np.floor(self.len / self.batch_size)) | ||
|
||
def __getitem__(self, index): | ||
"""Generate one batch of data | ||
:param index: index of the batch | ||
:return: X and y when fitting. X only when predicting | ||
""" | ||
# Generate indexes of the batch | ||
indexes = self.indexes[index * self.batch_size:(index + 1) * self.batch_size] | ||
|
||
# Download data by indexes | ||
X, y = [], [] | ||
for i in indexes: | ||
X.append(imread(self.data_paths[i])) | ||
y.append(get_label(self.labels_paths[i])) | ||
|
||
return X, y | ||
|
||
def on_epoch_end(self): | ||
"""Updates indexes after each epoch""" | ||
self.indexes = np.arange(self.len) | ||
if self.shuffle: | ||
np.random.shuffle(self.indexes) |
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,77 @@ | ||
import os | ||
|
||
import numpy as np | ||
from PIL import Image | ||
from tqdm import tqdm | ||
|
||
|
||
# def fix_dataset_labels(labels_path, colors=None): | ||
# if colors is None: | ||
# colors = { # RGB | ||
# (0, 0, 255): 0, # Wall | ||
# (0, 0, 170): 1, # Background | ||
# (255, 255, 0): 2, # Window (closed) | ||
# (0, 85, 255): 2, # Window | ||
# (0, 170, 255): 7, # Door | ||
# (170, 0, 0): 8, # Shop | ||
# (170, 255, 85): 3, # Balcony | ||
# (255, 85, 0): 6, # Molding | ||
# (255, 3, 0): 11, # Pillar | ||
# (0, 255, 255): 12, # Cornice | ||
# (85, 255, 170): 4, # Sill | ||
# (255, 170, 0): 9, # Deco | ||
# # (): 11, # Blind | ||
# } | ||
# | ||
# try: | ||
# os.mkdir(labels_path + "_FIXED/") | ||
# except: | ||
# pass | ||
# | ||
# files = [f for f in os.listdir(labels_path) if f[-4:] in [".jpg", ".png"]] | ||
# for id, image_name in enumerate(tqdm(files)): | ||
# image_path = labels_path + "/" + image_name | ||
# image = cv.imread(image_path) | ||
# | ||
# for h in range(len(image)): | ||
# for w in range(len(image[h])): | ||
# c = image[h][w] | ||
# for key, value in colors.items(): | ||
# if c[2] in range(key[0] - 3, key[0] + 3) and c[1] in range(key[1] - 2, key[1] + 3) and \ | ||
# c[0] in range(key[2] - 2, key[2] + 3): | ||
# image[h][w] = value | ||
# break | ||
# | ||
# image = cv.cvtColor(image, cv.COLOR_BGR2GRAY) | ||
# cv.imwrite(labels_path + "_FIXED/" + image_name, image) | ||
|
||
|
||
# def show_batch_photos(facades_class): | ||
# x_batch, y_batch = next(facades_class.train_generator) | ||
# for i in range(0, facades_class.batch_size): | ||
# x = x_batch[i] | ||
# y = y_batch[i] | ||
# | ||
# plt.imshow(x) | ||
# plt.show() # TODO: Check needing two | ||
# plt.imshow(y) | ||
# plt.show() | ||
|
||
|
||
def load_images_from_folder(dir, shape): | ||
files = [file for file in os.listdir(dir) if file.endswith((".png", ".jpg"))] | ||
result = [] | ||
|
||
for image_name in tqdm(files, dir): | ||
image_path = dir + "/" + image_name | ||
image = Image.open(image_path) | ||
image_resized = image.resize(shape[:-1], Image.ANTIALIAS) | ||
image_numpy = np.array(image_resized) | ||
if shape[-1] == 1: | ||
image_numpy = np.expand_dims(image_numpy, axis=-1) | ||
|
||
result.append(image_numpy) | ||
|
||
return np.array(result) | ||
|
||
|