Spaces:
Paused
Paused
Dean
commited on
Commit
•
13f0309
1
Parent(s):
479e632
Successfully configured the dataloader and trained for one epoch. Results are not so good, but it's something. Still the Fastaiv1 looked better qualitatively
Browse files- dvc.lock +5 -5
- src/code/make_dataset.py +3 -1
- src/code/training.py +16 -2
dvc.lock
CHANGED
@@ -3,21 +3,21 @@ process_data:
|
|
3 |
src/data/processed
|
4 |
deps:
|
5 |
- path: src/code/make_dataset.py
|
6 |
-
md5:
|
7 |
- path: src/data/raw/nyu_depth_v2_labeled.mat
|
8 |
md5: 520609c519fba3ba5ac58c8fefcc3530
|
9 |
- path: src/data/raw/splits.mat
|
10 |
md5: 08e3c3aea27130ac7c01ffd739a4535f
|
11 |
outs:
|
12 |
- path: src/data/processed/
|
13 |
-
md5:
|
14 |
train:
|
15 |
cmd: python3 src/code/training.py src/data/processed
|
16 |
deps:
|
17 |
- path: src/code/training.py
|
18 |
-
md5:
|
19 |
- path: src/data/processed/
|
20 |
-
md5:
|
21 |
outs:
|
22 |
- path: src/models/
|
23 |
-
md5:
|
|
|
3 |
src/data/processed
|
4 |
deps:
|
5 |
- path: src/code/make_dataset.py
|
6 |
+
md5: 726bf2bed948f73c5c342a96d017539e
|
7 |
- path: src/data/raw/nyu_depth_v2_labeled.mat
|
8 |
md5: 520609c519fba3ba5ac58c8fefcc3530
|
9 |
- path: src/data/raw/splits.mat
|
10 |
md5: 08e3c3aea27130ac7c01ffd739a4535f
|
11 |
outs:
|
12 |
- path: src/data/processed/
|
13 |
+
md5: 77adb8603dbf31f3b272e0f51b6c2c29.dir
|
14 |
train:
|
15 |
cmd: python3 src/code/training.py src/data/processed
|
16 |
deps:
|
17 |
- path: src/code/training.py
|
18 |
+
md5: 1d5f2b07b208bf062526e5ebfddca043
|
19 |
- path: src/data/processed/
|
20 |
+
md5: 77adb8603dbf31f3b272e0f51b6c2c29.dir
|
21 |
outs:
|
22 |
- path: src/models/
|
23 |
+
md5: e6f3667c5e3ff28faaf9172adab28107.dir
|
src/code/make_dataset.py
CHANGED
@@ -44,7 +44,9 @@ import cv2
|
|
44 |
def convert_image(i, scene, depth, image, folder):
|
45 |
img_depth = depth * 1000.0
|
46 |
img_depth_uint16 = img_depth.astype(np.uint16)
|
47 |
-
|
|
|
|
|
48 |
|
49 |
image = image[:, :, ::-1]
|
50 |
image_black_boundary = np.zeros((480, 640, 3), dtype=np.uint8)
|
|
|
44 |
def convert_image(i, scene, depth, image, folder):
|
45 |
img_depth = depth * 1000.0
|
46 |
img_depth_uint16 = img_depth.astype(np.uint16)
|
47 |
+
normalized_depth = np.zeros(img_depth_uint16.shape)
|
48 |
+
normalized_depth = cv2.normalize(img_depth_uint16, normalized_depth, 0, 255, cv2.NORM_MINMAX)
|
49 |
+
cv2.imwrite("%s/%05d_depth.png" % (folder, i), normalized_depth)
|
50 |
|
51 |
image = image[:, :, ::-1]
|
52 |
image_black_boundary = np.zeros((480, 640, 3), dtype=np.uint8)
|
src/code/training.py
CHANGED
@@ -3,6 +3,20 @@ import sys
|
|
3 |
from fastai2.vision.all import *
|
4 |
from torchvision.utils import save_image
|
5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
def get_y_fn(x):
|
8 |
y = str(x.absolute()).replace('.jpg', '_depth.png')
|
@@ -13,7 +27,7 @@ def get_y_fn(x):
|
|
13 |
|
14 |
def create_data(data_path):
|
15 |
fnames = get_files(data_path/'train', extensions='.jpg')
|
16 |
-
data =
|
17 |
return data
|
18 |
|
19 |
|
@@ -23,7 +37,7 @@ if __name__ == "__main__":
|
|
23 |
sys.exit(0)
|
24 |
|
25 |
data = create_data(Path(sys.argv[1]))
|
26 |
-
learner = unet_learner(data, resnet34, metrics=rmse, wd=1e-2, n_out=
|
27 |
learner.fine_tune(1)
|
28 |
|
29 |
learner.save('model')
|
|
|
3 |
from fastai2.vision.all import *
|
4 |
from torchvision.utils import save_image
|
5 |
|
6 |
+
class ImageImageDataLoaders(DataLoaders):
|
7 |
+
"Basic wrapper around several `DataLoader`s with factory methods for Image to Image problems"
|
8 |
+
@classmethod
|
9 |
+
@delegates(DataLoaders.from_dblock)
|
10 |
+
def from_label_func(cls, path, fnames, label_func, valid_pct=0.2, seed=None, item_tfms=None, batch_tfms=None, **kwargs):
|
11 |
+
"Create from list of `fnames` in `path`s with `label_func`."
|
12 |
+
dblock = DataBlock(blocks=(ImageBlock(cls=PILImage), ImageBlock(cls=PILImageBW)),
|
13 |
+
splitter=RandomSplitter(valid_pct, seed=seed),
|
14 |
+
get_y=label_func,
|
15 |
+
item_tfms=item_tfms,
|
16 |
+
batch_tfms=batch_tfms)
|
17 |
+
res = cls.from_dblock(dblock, fnames, path=path, **kwargs)
|
18 |
+
return res
|
19 |
+
|
20 |
|
21 |
def get_y_fn(x):
|
22 |
y = str(x.absolute()).replace('.jpg', '_depth.png')
|
|
|
27 |
|
28 |
def create_data(data_path):
|
29 |
fnames = get_files(data_path/'train', extensions='.jpg')
|
30 |
+
data = ImageImageDataLoaders.from_label_func(data_path/'train', seed=42, bs=4, num_workers=0, fnames=fnames, label_func=get_y_fn)
|
31 |
return data
|
32 |
|
33 |
|
|
|
37 |
sys.exit(0)
|
38 |
|
39 |
data = create_data(Path(sys.argv[1]))
|
40 |
+
learner = unet_learner(data, resnet34, metrics=rmse, wd=1e-2, n_out=3, loss_func=MSELossFlat(), path='src/')
|
41 |
learner.fine_tune(1)
|
42 |
|
43 |
learner.save('model')
|