Skip to content

Commit eb126b5

Browse files
committed
loader returns correct order of ims array (N,C,H,W)
Added dataset loading to classifier
1 parent 3ca1804 commit eb126b5

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

loadCOCO.py

+1
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ def loadCOCO(dataset_folder):
110110
images = np.array(images, dtype='float32')
111111
images /= 255.0 # Span 0 ~ 1
112112
images = (images*2) - 1 # Span -1 ~ 1
113+
images = np.transpose(images, (0, 3, 1, 2))
113114

114115
return (images, np.array(labels))
115116

unet.py

+15-2
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@
66
import torch.nn as nn
77
import torch.nn.functional as F
88
import torch.optim as optim
9+
from torch.utils.data import TensorDataset
10+
11+
from loadCOCO import loadCOCO
912

1013

1114
class Net(nn.Module):
1215
def __init__(self):
1316
super(Net, self).__init__()
14-
self.conv64 = nn.Conv2d(1, 64, 3, padding=1)
17+
self.conv64 = nn.Conv2d(3, 64, 3, padding=1)
1518
self.conv128 = nn.Conv2d(64, 128, 3, padding=1)
1619
self.conv256 = nn.Conv2d(128, 256, 3, padding=1)
1720
self.conv512 = nn.Conv2d(256, 512, 3, padding=1)
@@ -24,7 +27,7 @@ def __init__(self):
2427
self.dconv256 = nn.Conv2d(256, 128, 3, padding=1)
2528
self.upconv128 = nn.ConvTranspose2d(128, 64, 2, stride=2)
2629
self.dconv128 = nn.Conv2d(128, 64, 3, padding=1)
27-
self.conv1 = nn.Conv2d(64, 2, 1)
30+
self.conv1 = nn.Conv2d(64, 182, 1)
2831
self.pool = nn.MaxPool2d(2, 2)
2932

3033
def forward(self, x):
@@ -51,6 +54,16 @@ def forward(self, x):
5154
###########
5255
# Load Dataset #
5356
###########
57+
ims, labs = loadCOCO("/home/toni/Data/COCOstuff/")
58+
imsT = torch.Tensor(ims)
59+
labsT = torch.ByteTensor(labs)
60+
trainset = TensorDataset(imsT, labsT)
61+
trainloader = torch.utils.data.DataLoader(
62+
trainset,
63+
batch_size=4,
64+
shuffle=True,
65+
num_workers=2
66+
)
5467

5568

5669
net = Net()

0 commit comments

Comments
 (0)