luxmorocco commited on
Commit
9d85691
1 Parent(s): 3a60abf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -71
app.py CHANGED
@@ -60,77 +60,6 @@ class VinDetector(pl.LightningModule):
60
  scheduler = torch.optim.lr_scheduler.CosineAnnealingLR(optimizer, T_max=6, eta_min=0, verbose=True)
61
  return [optimizer], [scheduler]
62
 
63
-
64
- #VBDDataset Class
65
- class VBDDataset(Dataset):
66
-
67
- def __init__(self, dataframe, image_dir, transforms=None, phase='train'):
68
- super().__init__()
69
-
70
-
71
- self.image_ids = dataframe['image_id'].unique()
72
- self.df = dataframe
73
- self.image_dir = image_dir
74
- self.transforms = transforms
75
- self.phase = phase
76
-
77
- def __getitem__(self, idx):
78
-
79
- image_id = self.image_ids[idx]
80
- records = self.df[self.df['image_id'] == image_id]
81
-
82
-
83
- image = cv2.imread(f'{self.image_dir}/{image_id}.png', cv2.IMREAD_COLOR)
84
- image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB).astype(np.float32)
85
- image /= 255.0
86
-
87
-
88
- if self.phase == 'test':
89
- if self.transforms:
90
- sample = {
91
- 'image': image,
92
- }
93
- sample = self.transforms(**sample)
94
- image = sample['image']
95
- return image, image_id
96
-
97
-
98
- boxes = records[['x_min', 'y_min', 'x_max', 'y_max']].values
99
-
100
-
101
- area = (boxes[:, 3] - boxes[:, 1]) * (boxes[:, 2] - boxes[:, 0])
102
- area = torch.as_tensor(area, dtype=torch.float32)
103
-
104
-
105
- labels = torch.squeeze(torch.as_tensor((records.class_id.values+1,), dtype=torch.int64))
106
- iscrowd = torch.zeros((records.shape[0],), dtype=torch.int64)
107
-
108
-
109
- target = {}
110
- target['boxes'] = boxes
111
- target['labels'] = labels
112
- target['area'] = area
113
- target['image_id'] = torch.tensor([idx])
114
- target['iscrowd'] = iscrowd
115
-
116
-
117
- if self.transforms:
118
- sample = {
119
- 'image': image,
120
- 'bboxes': target['boxes'],
121
- 'labels': labels
122
- }
123
- sample = self.transforms(**sample)
124
- image = sample['image']
125
-
126
- target['boxes'] = torch.as_tensor(sample['bboxes'])
127
-
128
- return image, target
129
-
130
- def __len__(self):
131
-
132
- return self.image_ids.shape[0]
133
-
134
 
135
  def get_train_transform():
136
  return A.Compose([
 
60
  scheduler = torch.optim.lr_scheduler.CosineAnnealingLR(optimizer, T_max=6, eta_min=0, verbose=True)
61
  return [optimizer], [scheduler]
62
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63
 
64
  def get_train_transform():
65
  return A.Compose([