-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcloudSet.py
More file actions
66 lines (57 loc) · 1.89 KB
/
Copy pathcloudSet.py
File metadata and controls
66 lines (57 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import os
import gc
import cv2
import time
import tqdm
import random
import collections
import numpy as np
import pandas as pd
import seaborn as sns
from PIL import Image
from functools import partial
import matplotlib.pyplot as plt
from tqdm.notebook import tqdm as tq
from sklearn.model_selection import StratifiedKFold
from sklearn.metrics import roc_auc_score
import torch
import torchvision
import torch.nn as nn
import torch.optim as optim
import torch.nn.functional as F
from torch.optim import lr_scheduler
import torchvision.transforms as transforms
from torch.utils.data.sampler import SubsetRandomSampler
from torch.utils.data import TensorDataset, DataLoader, Dataset
from torch.optim.lr_scheduler import StepLR, ReduceLROnPlateau
# ablumentations for easy image augmentation for input as well as output
import albumentations as albu
# from albumentations import torch as AT
plt.style.use("bmh")
from utils import *
class CloudDataset(Dataset):
def __init__(
self,
df: pd.DataFrame = None,
datatype: str = "train",
img_ids: np.array = None,
transforms=albu.Compose([albu.HorizontalFlip()]),
img_paths="understanding_cloud_organization/train_image/",
):
self.df = df
self.data_folder = f"{img_paths}"
self.img_ids = img_ids
self.transforms = transforms
# self.masks = make_mask_all(self.df)
def __getitem__(self, idx):
image_name = self.img_ids[idx]
mask = make_mask(self.df, image_name)
image_path = os.path.join(self.data_folder, image_name)
img = cv2.imread(image_path)
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
augmented = self.transforms(image=img, mask=mask)
img = np.transpose(augmented["image"], [2, 0, 1])
mask = np.transpose(augmented["mask"], [2, 0, 1])
return img, mask
def __len__(self):
return len(self.img_ids)