-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated preprocessing and convolution
- Loading branch information
1 parent
08a0c7b
commit 09afa4d
Showing
12 changed files
with
228 additions
and
101 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
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file not shown.
File renamed without changes.
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,47 +1,70 @@ | ||
import os | ||
os.environ['KMP_DUPLICATE_LIB_OK']='True' | ||
|
||
import os | ||
import random | ||
import numpy as np | ||
import torch | ||
from skimage import io, transform | ||
from skimage import io | ||
import matplotlib.pyplot as plt | ||
from torch.utils.data import Dataset, DataLoader | ||
from torchvision import transforms, utils | ||
|
||
os.environ['KMP_DUPLICATE_LIB_OK']='True' | ||
|
||
class SatelliteElevationDataset(Dataset): | ||
'''Satellite Elevation Dataset''' | ||
|
||
def __init__(self, root_dir, tile_ct): | ||
self.root_dir = root_dir | ||
self.filenames = [] | ||
for i in range(0, tile_ct * 256, 256): | ||
for j in range(0, tile_ct * 256, 256): | ||
self.filenames.append(f"{i},{j}c.jpg") | ||
self.filenames.append(f"{i},{j}.jpg") | ||
def __init__(self, root_dirs, tile_cts, transform=None): | ||
''' | ||
Arguments: | ||
root_dir (list[string]): List of paths to the root directory of the image data | ||
tile_ct (int): number of 51.2 km squares per side of area from which data was collected | ||
transform (callable, optional): Optional transform to be applied on a sample | ||
''' | ||
self.transform = transform | ||
self.elevation_imgs = [] | ||
self.satellite_imgs = [] | ||
for root_dir, tile_ct in zip(root_dirs, tile_cts): | ||
for i in range(0, tile_ct * 256, 256): | ||
for j in range(0, tile_ct * 256, 256): | ||
self.elevation_imgs.append(os.path.join(root_dir + f"{i},{j}c.jpg")) | ||
self.satellite_imgs.append(os.path.join(root_dir + f"{i},{j}.jpg")) | ||
|
||
def __len__(self): | ||
return len(self.filenames) | ||
return len(self.elevation_imgs) | ||
|
||
def __getitem__(self, idx): | ||
if torch.is_tensor(idx): | ||
idx = idx.tolist() | ||
img_name = os.path.join(self.root_dir + self.filenames[idx]) | ||
image = io.imread(img_name) | ||
sample = {'image': image} | ||
# os.path.join(self.root_dir + self.elevation_imgs[idx]) | ||
elevation_img_name = self.elevation_imgs[idx] | ||
satellite_img_name = self.satellite_imgs[idx] | ||
elevation_img = io.imread(elevation_img_name) | ||
satellite_img = io.imread(satellite_img_name) | ||
sample = {'elevation': elevation_img, 'satellite': satellite_img} | ||
if self.transform: | ||
sample = self.transform(sample) | ||
return sample | ||
|
||
def GetDataset(): | ||
return SatelliteElevationDataset("data/ANDES/", 12) | ||
# preprocessing: apply random jittering and mirroring to preprocess the training set | ||
def transform(sample): | ||
|
||
# print(len(sat_dataset)) | ||
# for sample in sat_dataset: | ||
# print(sample['image'].shape) | ||
transformation = transforms.Compose( | ||
[transforms.Resize(286), | ||
transforms.RandomCrop(256)]) | ||
flip = random.choice([transforms.RandomHorizontalFlip(0), transforms.RandomHorizontalFlip(1)]) | ||
|
||
# fig = plt.figure() | ||
elevation_img, satellite_img = sample['elevation'], sample['satellite'] | ||
|
||
# for i in range(0,17): | ||
# ax = plt.subplot(4,5, i+1) | ||
# plt.tight_layout() | ||
# sample = sat_dataset[i] | ||
# plt.imshow(sample['image']) | ||
elevation_img = transforms.ToTensor()(elevation_img) | ||
elevation_img = transformation(elevation_img) | ||
elevation_img = flip(elevation_img) | ||
|
||
# plt.show() | ||
|
||
satellite_img = transforms.ToTensor()(satellite_img) | ||
satellite_img = transformation(satellite_img) | ||
satellite_img = flip(satellite_img) | ||
|
||
return {'elevation': elevation_img, 'satellite': satellite_img} | ||
|
||
def GetDataset(): | ||
return SatelliteElevationDataset(["data/CALI/", "data/ANDES/"], [12, 12], transform=transform) |
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,18 @@ | ||
import torch | ||
import numpy as np | ||
from skimage import io, transform | ||
import matplotlib.pyplot as plt | ||
from torch.utils.data import Dataset, DataLoader | ||
from torchvision import transforms, utils | ||
from preprocess import GetDataset | ||
import random | ||
|
||
dataset = GetDataset() | ||
|
||
fig = plt.figure() | ||
sample = dataset[67] | ||
elevation_img = sample['elevation'] | ||
elevation_img = torch.transpose(elevation_img, 0, 2) | ||
elevation_img = torch.transpose(elevation_img, 1, 0) | ||
plt.imshow(elevation_img) | ||
plt.show() |