UMSN Files

This commit is contained in:
rajeevyasarla
2019-07-26 21:10:57 -04:00
parent f8be8accbf
commit 05f948d590
50 changed files with 4847 additions and 0 deletions
+1
View File
@@ -0,0 +1 @@
Binary file not shown.
+75
View File
@@ -0,0 +1,75 @@
import torch.utils.data as data
from PIL import Image
import os
import os.path
import numpy as np
import h5py
import glob
IMG_EXTENSIONS = [
'.jpg', '.JPG', '.jpeg', '.JPEG',
'.png', '.PNG', '.ppm', '.PPM', '.bmp', '.BMP',
]
def is_image_file(filename):
return any(filename.endswith(extension) for extension in IMG_EXTENSIONS)
def make_dataset(dir):
images = []
if not os.path.isdir(dir):
raise Exception('Check dataroot')
for root, _, fnames in sorted(os.walk(dir)):
for fname in fnames:
if is_image_file(fname):
path = os.path.join(dir, fname)
item = path
images.append(item)
return images
def default_loader(path):
return Image.open(path).convert('RGB')
class classification(data.Dataset):
def __init__(self, root, transform=None, loader=default_loader, seed=None):
# imgs = make_dataset(root)
# if len(imgs) == 0:
# raise(RuntimeError("Found 0 images in subfolders of: " + root + "\n"
# "Supported image extensions are: " + ",".join(IMG_EXTENSIONS)))
self.root = root
# self.imgs = imgs
self.transform = transform
self.loader = loader
if seed is not None:
np.random.seed(seed)
def __getitem__(self, _):
index = np.random.randint(1,self.__len__())
# path = self.imgs[index]
# img = self.loader(path)
#img = img.resize((w, h), Image.BILINEAR)
file_name=self.root+'/'+str(index)+'.h5'
f=h5py.File(file_name,'r')
haze_image=f['haze'][:]
label=f['label'][:]
label=label.mean()-1
haze_image=np.swapaxes(haze_image,0,2)
haze_image=np.swapaxes(haze_image,1,2)
# if self.transform is not None:
# # NOTE preprocessing for each pair of images
# imgA, imgB = self.transform(imgA, imgB)
return haze_image, label
def __len__(self):
train_list=glob.glob(self.root+'/*h5')
# print len(train_list)
return len(train_list)
# return len(self.imgs)
+133
View File
@@ -0,0 +1,133 @@
import torch.utils.data as data
from PIL import Image
import os
import os.path
import numpy as np
IMG_EXTENSIONS = [
'.jpg', '.JPG', '.jpeg', '.JPEG',
'.png', '.PNG', '.ppm', '.PPM', '.bmp', '.BMP', '',
]
def is_image_file(filename):
return any(filename.endswith(extension) for extension in IMG_EXTENSIONS)
def make_dataset(dir):
images = []
if not os.path.isdir(dir):
raise Exception('Check dataroot')
for root, _, fnames in sorted(os.walk(dir)):
for fname in fnames:
if is_image_file(fname):
path = os.path.join(dir, fname)
item = path
images.append(item)
return images
def default_loader(path):
return Image.open(path).convert('RGB')
class pix2pix(data.Dataset):
def __init__(self, root, transform=None, loader=default_loader, seed=None):
imgs = make_dataset(root)
if len(imgs) == 0:
raise(RuntimeError("Found 0 images in subfolders of: " + root + "\n"
"Supported image extensions are: " + ",".join(IMG_EXTENSIONS)))
self.root = root
self.imgs = imgs
self.transform = transform
self.loader = loader
if seed is not None:
np.random.seed(seed)
def __getitem__(self, index):
# index = np.random.randint(self.__len__(), size=1)[0]
# index = np.random.randint(self.__len__(), size=1)[0]+1
# index = np.random.randint(self.__len__(), size=1)[0]
# index_folder = np.random.randint(1,4)
index_folder = np.random.randint(0,1)
index_sub = np.random.randint(2, 5)
label=index_folder
if index_folder==0:
path='/home/openset/Desktop/derain2018/facades/training2'+'/'+str(index)+'.jpg'
if index_folder==1:
if index_sub<4:
path='/home/openset/Desktop/derain2018/facades/DB_Rain_new/Rain_Heavy/train2018new'+'/'+str(index)+'.jpg'
if index_sub==4:
index = np.random.randint(0,400)
path='/home/openset/Desktop/derain2018/facades/DB_Rain/Rain_Heavy/trainnew'+'/'+str(index)+'.jpg'
if index_folder==2:
if index_sub<4:
path='/home/openset/Desktop/derain2018/facades/DB_Rain_new/Rain_Medium/train2018new'+'/'+str(index)+'.jpg'
if index_sub==4:
index = np.random.randint(0,400)
path='/home/openset/Desktop/derain2018/facades/DB_Rain/Rain_Medium/trainnew'+'/'+str(index)+'.jpg'
if index_folder==3:
if index_sub<4:
path='/home/openset/Desktop/derain2018/facades/DB_Rain_new/Rain_Light/train2018new'+'/'+str(index)+'.jpg'
if index_sub==4:
index = np.random.randint(0,400)
path='/home/openset/Desktop/derain2018/facades/DB_Rain/Rain_Light/trainnew'+'/'+str(index)+'.jpg'
# img = self.loader(path)
img = self.loader(path)
# NOTE: img -> PIL Image
# w, h = img.size
# w, h = 1024, 512
# img = img.resize((w, h), Image.BILINEAR)
# pix = np.array(I)
#
# r = 16
# eps = 1
#
# I = img.crop((0, 0, w/2, h))
# pix = np.array(I)
# base=guidedfilter(pix, pix, r, eps)
# base = PIL.Image.fromarray(numpy.uint8(base))
#
#
#
# imgA=base
# imgB=I-base
# imgC = img.crop((w/2, 0, w, h))
w, h = img.size
# img = img.resize((w, h), Image.BILINEAR)
# NOTE: split a sample into imgA and imgB
imgA = img.crop((0, 0, w/2, h))
# imgC = img.crop((2*w/3, 0, w, h))
imgB = img.crop((w/2, 0, w, h))
if self.transform is not None:
# NOTE preprocessing for each pair of images
# imgA, imgB, imgC = self.transform(imgA, imgB, imgC)
imgA, imgB = self.transform(imgA, imgB)
return imgA, imgB, label
def __len__(self):
# return 679
print(len(self.imgs))
return len(self.imgs)
Binary file not shown.
+109
View File
@@ -0,0 +1,109 @@
import torch.utils.data as data
from PIL import Image
import os
import os.path
import numpy as np
import h5py
import glob
import scipy.ndimage
IMG_EXTENSIONS = [
'.jpg', '.JPG', '.jpeg', '.JPEG',
'.png', '.PNG', '.ppm', '.PPM', '.bmp', '.BMP',
]
def is_image_file(filename):
return any(filename.endswith(extension) for extension in IMG_EXTENSIONS)
def make_dataset(dir):
images = []
if not os.path.isdir(dir):
raise Exception('Check dataroot')
for root, _, fnames in sorted(os.walk(dir)):
for fname in fnames:
if is_image_file(fname):
path = os.path.join(dir, fname)
item = path
images.append(item)
return images
def default_loader(path):
return Image.open(path).convert('RGB')
class pix2pix(data.Dataset):
def __init__(self, root, transform=None, loader=default_loader, seed=None):
# imgs = make_dataset(root)
# if len(imgs) == 0:
# raise(RuntimeError("Found 0 images in subfolders of: " + root + "\n"
# "Supported image extensions are: " + ",".join(IMG_EXTENSIONS)))
self.root = root
# self.imgs = imgs
self.transform = transform
self.loader = loader
if seed is not None:
np.random.seed(seed)
def __getitem__(self, _):
index = np.random.randint(1,self.__len__())
# index = np.random.randint(self.__len__(), size=1)[0]
# path = self.imgs[index]
# img = self.loader(path)
#img = img.resize((w, h), Image.BILINEAR)
file_name=self.root+'/'+str(index)+'.h5'
f=h5py.File(file_name,'r')
haze_image=f['haze'][:]
trans_map=f['trans'][:]
ato_map=f['ato'][:]
GT=f['gt'][:]
haze_image=np.swapaxes(haze_image,0,2)
trans_map=np.swapaxes(trans_map,0,2)
ato_map=np.swapaxes(ato_map,0,2)
GT=np.swapaxes(GT,0,2)
haze_image=np.swapaxes(haze_image,1,2)
trans_map=np.swapaxes(trans_map,1,2)
ato_map=np.swapaxes(ato_map,1,2)
GT=np.swapaxes(GT,1,2)
# if np.random.uniform()>0.5:
# haze_image=np.flip(haze_image,2).copy()
# GT = np.flip(GT, 2).copy()
# trans_map=np.flip(trans_map, 2).copy()
# if np.random.uniform()>0.5:
# angle = np.random.uniform(-10, 10)
# haze_image=scipy.ndimage.interpolation.rotate(haze_image, angle)
# GT = scipy.ndimage.interpolation.rotate(GT, angle)
# if np.random.uniform()>0.5:
# angle = np.random.uniform(-10, 10)
# haze_image=scipy.ndimage.interpolation.rotate(haze_image, angle)
# GT = scipy.ndimage.interpolation.rotate(GT, angle)
# if np.random.uniform()>0.5:
# std = np.random.uniform(0.2, 1.2)
# haze_image = scipy.ndimage.filters.gaussian_filter(haze_image, std,mode='constant')
# haze_image=np.random.uniform(-10/5000,10/5000,size=haze_image.shape)
# haze_image = np.maximum(0, haze_image)
# if self.transform is not None:
# # NOTE preprocessing for each pair of images
# imgA, imgB = self.transform(imgA, imgB)
return haze_image, GT, trans_map, ato_map
def __len__(self):
train_list=glob.glob(self.root+'/*h5')
# print len(train_list)
return len(train_list)
# return len(self.imgs)
+88
View File
@@ -0,0 +1,88 @@
import torch.utils.data as data
from PIL import Image
import os
import os.path
import numpy as np
IMG_EXTENSIONS = [
'.jpg', '.JPG', '.jpeg', '.JPEG',
'.png', '.PNG', '.ppm', '.PPM', '.bmp', '.BMP', '',
]
def is_image_file(filename):
return any(filename.endswith(extension) for extension in IMG_EXTENSIONS)
def make_dataset(dir):
images = []
if not os.path.isdir(dir):
raise Exception('Check dataroot')
for root, _, fnames in sorted(os.walk(dir)):
for fname in fnames:
if is_image_file(fname):
path = os.path.join(dir, fname)
item = path
images.append(item)
return images
def default_loader(path):
return Image.open(path).convert('RGB')
class pix2pix(data.Dataset):
def __init__(self, root, transform=None, loader=default_loader, seed=None):
imgs = make_dataset(root)
if len(imgs) == 0:
raise(RuntimeError("Found 0 images in subfolders of: " + root + "\n"
"Supported image extensions are: " + ",".join(IMG_EXTENSIONS)))
self.root = root
self.imgs = imgs
self.transform = transform
self.loader = loader
if seed is not None:
np.random.seed(seed)
def __getitem__(self, index):
index_sub = np.random.randint(0, 3)
label=index_sub
if index_sub==0:
index = np.random.randint(0,4000)
path='/media/openset/Z/derain2018/facades/DID-MDN-training/Rain_Heavy/train2018new'+'/'+str(index)+'.jpg'
if index_sub==1:
index = np.random.randint(0,4000)
path='/media/openset/Z/derain2018/facades/DID-MDN-training/Rain_Medium/train2018new'+'/'+str(index)+'.jpg'
if index_sub==2:
index = np.random.randint(0,4000)
path='/media/openset/Z/derain2018/facades/DID-MDN-training/Rain_Light/train2018new'+'/'+str(index)+'.jpg'
img = self.loader(path)
w, h = img.size
# NOTE: split a sample into imgA and imgB
imgA = img.crop((0, 0, w/2, h))
imgB = img.crop((w/2, 0, w, h))
if self.transform is not None:
# NOTE preprocessing for each pair of images
imgA, imgB = self.transform(imgA, imgB)
return imgA, imgB, label
def __len__(self):
# return 679
# print(len(self.imgs))
return len(self.imgs)
Binary file not shown.
+139
View File
@@ -0,0 +1,139 @@
import torch.utils.data as data
from PIL import Image
import os
import os.path
import numpy as np
import cv2
# from guidedfilter import guidedfilter
# import guidedfilter.guidedfilter as guidedfilter
IMG_EXTENSIONS = [
'.jpg', '.JPG', '.jpeg', '.JPEG',
'.png', '.PNG', '.ppm', '.PPM', '.bmp', '.BMP', '',
]
def is_image_file(filename):
return any(filename.endswith(extension) for extension in IMG_EXTENSIONS)
def make_dataset(dir):
images = []
if not os.path.isdir(dir):
raise Exception('Check dataroot')
for root, _, fnames in sorted(os.walk(dir)):
for fname in fnames:
if is_image_file(fname):
path = os.path.join(dir, fname)
item = path
images.append(item)
return images
def default_loader(path):
return Image.open(path).convert('RGB')
class pix2pix_val(data.Dataset):
def __init__(self, root, transform=None, loader=default_loader, seed=None):
imgs = make_dataset(root)
if len(imgs) == 0:
raise(RuntimeError("Found 0 images in subfolders of: " + root + "\n"
"Supported image extensions are: " + ",".join(IMG_EXTENSIONS)))
self.root = root
self.imgs = imgs
self.transform = transform
self.loader = loader
if seed is not None:
np.random.seed(seed)
def __getitem__(self, index):
# index = np.random.randint(self.__len__(), size=1)[0]
# index = np.random.randint(self.__len__(), size=1)[0]
path = self.imgs[index]
if index>75000:
index = index%75000+10
path=self.root+'/'+'%06d'%(index+1)+'.png'
index_folder = np.random.randint(0,4)
label=index_folder
# path='/home/openset/Desktop/derain2018/facades/DB_Rain_test/Rain_Heavy/test2018'+'/'+str(index)+'.jpg'
img = self.loader(path)
# # NOTE: img -> PIL Image
# w, h = img.size
# w, h = 1024, 512
# img = img.resize((w, h), Image.BILINEAR)
# # NOTE: split a sample into imgA and imgB
# imgA = img.crop((0, 0, w/2, h))
# imgB = img.crop((w/2, 0, w, h))
# if self.transform is not None:
# # NOTE preprocessing for each pair of images
# imgA, imgB = self.transform(imgA, imgB)
# return imgA, imgB
# w, h = 1536, 512
# img = img.resize((w, h), Image.BILINEAR)
#
#
# # NOTE: split a sample into imgA and imgB
# imgA = img.crop((0, 0, w/3, h))
# imgC = img.crop((2*w/3, 0, w, h))
#
# imgB = img.crop((w/3, 0, 2*w/3, h))
# w, h = 1024, 512
# img = img.resize((w, h), Image.BILINEAR)
#
# r = 16
# eps = 1
#
# # I = img.crop((0, 0, w/2, h))
# # pix = np.array(I)
# # print
# # base[idx,:,:,:]=guidedfilter(pix[], pix[], r, eps)
# # base[]=guidedfilter(pix[], pix[], r, eps)
# # base[]=guidedfilter(pix[], pix[], r, eps)
#
#
# # base = PIL.Image.fromarray(numpy.uint8(base))
#
# # NOTE: split a sample into imgA and imgB
# imgA = img.crop((0, 0, w/3, h))
# imgC = img.crop((2*w/3, 0, w, h))
#
# imgB = img.crop((w/3, 0, 2*w/3, h))
# imgA=base
# imgB=I-base
# imgC = img.crop((w/2, 0, w, h))
w, h = img.size
#print(w,h)
# w, h = 586*2, 586
# img = img.resize((w, h), Image.BILINEAR)
# NOTE: split a sample into imgA and imgB
imgA = img.crop((0, 0, w/2, h))
# imgC = img.crop((2*w/3, 0, w, h))
imgB = img.crop((w/2, 0, w, h))
if self.transform is not None:
# NOTE preprocessing for each pair of images
# imgA, imgB, imgC = self.transform(imgA, imgB, imgC)
imgA, imgB = self.transform(img, img)
return imgA, imgB
def __len__(self):
return len(self.imgs)
Binary file not shown.
+1103
View File
File diff suppressed because it is too large Load Diff