Dean commited on
Commit
737e99e
2 Parent(s): a005e08 9296b0b

Merge branch 'simplifying-savta-depth' of OperationSavta/SavtaDepth into pipeline-setup

Browse files
.dvc/config CHANGED
@@ -1,5 +1,5 @@
1
  [core]
2
  analytics = false
3
- remote = dvc-remote
4
- ['remote "dvc-remote"']
5
- url = gs://dagshub-savta-depth
 
1
  [core]
2
  analytics = false
3
+ remote = origin
4
+ ['remote "origin"']
5
+ url = https://dagshub.com/OperationSavta/SavtaDepth.dvc
.gitignore CHANGED
@@ -6,3 +6,4 @@
6
  aws/
7
  google-cloud-sdk
8
  __pycache__/
 
 
6
  aws/
7
  google-cloud-sdk
8
  __pycache__/
9
+ env/
Notebooks/SavtaDepth_Colab.ipynb CHANGED
The diff for this file is too large to render. See raw diff
 
README.md CHANGED
@@ -4,6 +4,12 @@ Savta Depth is a collaborative *O*pen *S*ource *D*ata *S*cience project for mono
4
  Here you will find the code for the project, but also the data, models, pipelines and experiments. This means that the project is easily reproducible on any machine, but also that you can contribute to it as a data scientist.
5
 
6
  Have a great idea for how to improve the model? Want to add data and metrics to make it more explainable/fair? We'd love to get your help.
 
 
 
 
 
 
7
 
8
  ## Contributing Guide
9
  Here we'll list things we want to work on in the project as well as ways to start contributing.
@@ -16,9 +22,12 @@ If you'd like to take part, please follow the guide.
16
  #### Google Colab
17
  Google Colab can be looked at as your web connected, GPU powered IDE. Below is a link to a well-documented Colab notebook, that will load the code and data from this repository, enabling you to modify the code and re-run training. Notice that you still need to modify the code within the `src/code/` folder, adding cells should be used only for testing things out.
18
 
 
 
 
19
  In order to edit code files, you must save the notebook to your drive. You can do this by typing `ctrl+s` or `cmd+s` on mac.
20
 
21
- \>\> **[SavtaDepth Colab Environment](https://colab.research.google.com/drive/19027P09jiiN1C99-YGk4FPj0Ol9iXUIU?usp=sharing)** \<\<
22
 
23
  **_NOTE: The downside of this method (if you are not familiar with Colab) is that Google Colab will limit the amount of time an instance can be live, so you might be limited in your ability to train models for longer periods of time._**
24
 
@@ -26,9 +35,11 @@ This notebook is also a part of this project, in case it needs modification, in
26
 
27
  #### Local
28
  * Clone the repository you just forked by typing the following command in your terminal:
29
- ```bash
30
- $ git clone https://dagshub.com/<your-dagshub-username>/SavtaDepth.git
31
- ```
 
 
32
  * Create a virtual environment or Conda environment and activate it
33
  ```bash
34
  # Create the virtual environment
@@ -49,25 +60,22 @@ This notebook is also a part of this project, in case it needs modification, in
49
  * Pull the dvc files to your workspace by typing:
50
 
51
  ```bash
52
- $ dvc pull -r dvc-remote
53
  $ dvc checkout #use this to get the data, models etc
54
  ```
55
 
56
- **Note**: You might need to install and setup the tools to pull from a remote. Read more in [this guide](https://dagshub.com/docs/getting-started/set-up-remote-storage-for-data-and-models/) on how to setup Google Storage or AWS S3 access.
57
  * After you are finished your modification, make sure to do the following:
58
- * If you modified packages, make sure to freeze your virtualenv by typing in the terminal:
59
 
60
- ```bash
61
- $ make save_requirements
62
- ```
63
-
64
- * Push your code to DAGsHub, and your dvc managed files to your dvc remote. To setup a dvc remote please refer to [this guide](https://dagshub.com/docs/getting-started/set-up-remote-storage-for-data-and-models/).
65
 
66
  #### Docker
67
  * Clone the repository you just forked by typing the following command in your terminal:
68
- ```bash
69
- $ git clone https://dagshub.com/<your-dagshub-username>/SavtaDepth.git
70
- ```
 
 
71
  * To get your environment up and running docker is the best way to go. We use an instance of [MLWorkspace](https://github.com/ml-tooling/ml-workspace).
72
  * You can Just run the following commands to get it started.
73
 
@@ -106,19 +114,17 @@ This notebook is also a part of this project, in case it needs modification, in
106
  $ dvc checkout #use this to get the data, models etc
107
  ```
108
 
109
- **Note**: You might need to install and setup the tools to pull from a remote. Read more in [this guide](https://dagshub.com/docs/getting-started/set-up-remote-storage-for-data-and-models/) on how to setup Google Storage or AWS S3 access.
110
  * After you are finished your modification, make sure to do the following:
111
- * Freeze your virtualenv by typing in the terminal:
112
-
113
- ```bash
114
- $ make save_requirements
115
- ```
116
 
117
- * Push your code to DAGsHub, and your dvc managed files to your dvc remote. In order to setup a dvc remote please refer to [this guide](https://dagshub.com/docs/getting-started/set-up-remote-storage-for-data-and-models/).
118
 
119
  ---
120
  ### After pushing code and data to DAGsHub
121
  * Create a Pull Request on DAGsHub!
 
 
 
122
  * 🐶
123
 
124
  ### TODO:
 
4
  Here you will find the code for the project, but also the data, models, pipelines and experiments. This means that the project is easily reproducible on any machine, but also that you can contribute to it as a data scientist.
5
 
6
  Have a great idea for how to improve the model? Want to add data and metrics to make it more explainable/fair? We'd love to get your help.
7
+ ## Demo
8
+ **You can use [this notebook](https://colab.research.google.com/drive/1XU4DgQ217_hUMU1dllppeQNw3pTRlHy1?usp=sharing) to load a model from the project and run it on an image you uploaded, to get the depth map. Once it has been saved, you can download it to use on platforms that support it (e.g. Facebook) to create 3d photos.**
9
+
10
+ ![](https://i.ibb.co/r20HKpQ/savtadepthex.png)
11
+
12
+ \>\> **[Demo Notebook](https://colab.research.google.com/drive/1XU4DgQ217_hUMU1dllppeQNw3pTRlHy1?usp=sharing)** \<\<
13
 
14
  ## Contributing Guide
15
  Here we'll list things we want to work on in the project as well as ways to start contributing.
 
22
  #### Google Colab
23
  Google Colab can be looked at as your web connected, GPU powered IDE. Below is a link to a well-documented Colab notebook, that will load the code and data from this repository, enabling you to modify the code and re-run training. Notice that you still need to modify the code within the `src/code/` folder, adding cells should be used only for testing things out.
24
 
25
+ **You can also use this notebook to load a model from the project and run it on an image you uploaded, to get the depth map. Once it has been saved, you can download it to use on platforms that support it (e.g. Facebook) to create 3d photos.**
26
+
27
+
28
  In order to edit code files, you must save the notebook to your drive. You can do this by typing `ctrl+s` or `cmd+s` on mac.
29
 
30
+ \>\> **[SavtaDepth Colab Environment](https://colab.research.google.com/drive/1XU4DgQ217_hUMU1dllppeQNw3pTRlHy1?usp=sharing)** \<\<
31
 
32
  **_NOTE: The downside of this method (if you are not familiar with Colab) is that Google Colab will limit the amount of time an instance can be live, so you might be limited in your ability to train models for longer periods of time._**
33
 
 
35
 
36
  #### Local
37
  * Clone the repository you just forked by typing the following command in your terminal:
38
+
39
+ ```bash
40
+ $ git clone https://dagshub.com/<your-dagshub-username>/SavtaDepth.git
41
+ ```
42
+
43
  * Create a virtual environment or Conda environment and activate it
44
  ```bash
45
  # Create the virtual environment
 
60
  * Pull the dvc files to your workspace by typing:
61
 
62
  ```bash
63
+ $ dvc pull -r origin
64
  $ dvc checkout #use this to get the data, models etc
65
  ```
66
 
 
67
  * After you are finished your modification, make sure to do the following:
68
+ * If you modified packages, make sure to update the `requirements.txt` file accordingly.
69
 
70
+ * Push your code to DAGsHub, and your dvc managed files to your dvc remote. For reference on the commands needed, please refer to the Google Colab notebook section – [Commiting Your Work and Pushing Back to DAGsHub](https://colab.research.google.com/drive/1XU4DgQ217_hUMU1dllppeQNw3pTRlHy1?authuser=1#scrollTo=PAxz-29WhN12&line=1&uniqifier=1).
 
 
 
 
71
 
72
  #### Docker
73
  * Clone the repository you just forked by typing the following command in your terminal:
74
+
75
+ ```bash
76
+ $ git clone https://dagshub.com/<your-dagshub-username>/SavtaDepth.git
77
+ ```
78
+
79
  * To get your environment up and running docker is the best way to go. We use an instance of [MLWorkspace](https://github.com/ml-tooling/ml-workspace).
80
  * You can Just run the following commands to get it started.
81
 
 
114
  $ dvc checkout #use this to get the data, models etc
115
  ```
116
 
 
117
  * After you are finished your modification, make sure to do the following:
118
+ * If you modified packages, make sure to update the `requirements.txt` file accordingly.
 
 
 
 
119
 
120
+ * Push your code to DAGsHub, and your dvc managed files to your dvc remote. For reference on the commands needed, please refer to the Google Colab notebook section – [Commiting Your Work and Pushing Back to DAGsHub](https://colab.research.google.com/drive/1XU4DgQ217_hUMU1dllppeQNw3pTRlHy1?authuser=1#scrollTo=PAxz-29WhN12&line=1&uniqifier=1).
121
 
122
  ---
123
  ### After pushing code and data to DAGsHub
124
  * Create a Pull Request on DAGsHub!
125
+ * Explain what changes you are making.
126
+ * If your changes affect data or models, make sure they are pushed to your DAGsHub dvc remote, and are included in the PR.
127
+ * We will review your contribution ASAP, and merge it or start a discussion if needed.
128
  * 🐶
129
 
130
  ### TODO:
dvc.lock CHANGED
@@ -3,21 +3,31 @@ process_data:
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
 
 
 
3
  src/data/processed
4
  deps:
5
  - path: src/code/make_dataset.py
6
+ md5: fd5076d53909a47ce3b6598c26af6c97
7
+ size: 3783
8
  - path: src/data/raw/nyu_depth_v2_labeled.mat
9
  md5: 520609c519fba3ba5ac58c8fefcc3530
10
+ size: 2972037809
11
  - path: src/data/raw/splits.mat
12
  md5: 08e3c3aea27130ac7c01ffd739a4535f
13
+ size: 2626
14
  outs:
15
  - path: src/data/processed/
16
+ md5: d98a9647a37ab431bfa35815eb4afda0.dir
17
+ size: 232903470
18
+ nfiles: 2898
19
  train:
20
  cmd: python3 src/code/training.py src/data/processed
21
  deps:
22
  - path: src/code/training.py
23
+ md5: 9634e85cffa3cf72d3d3d7739e40969e
24
+ size: 1645
25
  - path: src/data/processed/
26
+ md5: d98a9647a37ab431bfa35815eb4afda0.dir
27
+ size: 232903470
28
+ nfiles: 2898
29
  outs:
30
  - path: src/models/
31
+ md5: 18d26ed378b1b5ac61425afe153fc076.dir
32
+ size: 494926829
33
+ nfiles: 1
requirements.txt CHANGED
@@ -1,107 +1,8 @@
1
- appdirs==1.4.4
2
- atpublic==2.0
3
- backcall==0.2.0
4
- blis==0.4.1
5
- cachetools==4.1.1
6
- catalogue==1.0.0
7
- certifi==2020.6.20
8
- cffi==1.14.2
9
- chardet==3.0.4
10
- colorama==0.4.3
11
- commonmark==0.9.1
12
- configobj==5.0.6
13
- cycler==0.10.0
14
- cymem==2.0.3
15
- dataclasses==0.6
16
- decorator==4.4.2
17
- dictdiffer==0.8.1
18
- distro==1.5.0
19
- dpath==2.0.1
20
- dvc==1.9.1
21
- fastai==2.0.0
22
- fastcore==1.0.0
23
- fastprogress==1.0.0
24
- flatten-json==0.1.7
25
- flufl.lock==3.2
26
- funcy==1.14
27
- future==0.18.2
28
- gitdb==4.0.5
29
- GitPython==3.1.7
30
- google-api-core==1.22.1
31
- google-auth==1.20.1
32
- google-cloud-core==1.4.1
33
- google-cloud-storage==1.19.0
34
- google-crc32c==0.1.0
35
- google-resumable-media==0.7.1
36
- googleapis-common-protos==1.52.0
37
- grandalf==0.6
38
  h5py==2.10.0
39
- idna==2.10
40
- importlib-metadata==1.7.0
41
- ipykernel==5.3.4
42
- ipython==7.17.0
43
- ipython-genutils==0.2.0
44
- jedi==0.17.2
45
- joblib==0.16.0
46
- jsonpath-ng==1.5.1
47
- kiwisolver==1.2.0
48
- matplotlib==3.3.1
49
- murmurhash==1.0.2
50
- nanotime==0.5.2
51
- networkx==2.4
52
- numpy==1.19.1
53
- olefile==0.46
54
  opencv-python==4.4.0.42
55
- packaging==20.4
56
- pandas==1.1.1
57
- parso==0.7.1
58
- pathspec==0.8.0
59
- pexpect==4.8.0
60
- pickleshare==0.7.5
61
- Pillow==7.2.0
62
- pip==20.2.2
63
- plac==1.1.3
64
- ply==3.11
65
- preshed==3.0.2
66
- prompt-toolkit==3.0.6
67
- protobuf==3.13.0
68
- ptyprocess==0.6.0
69
- pyasn1==0.4.8
70
- pyasn1-modules==0.2.8
71
- pycparser==2.20
72
- pydot==1.4.1
73
- Pygments==2.6.1
74
- pygtrie==2.3.2
75
- pyparsing==2.4.7
76
- python-dateutil==2.8.1
77
- pytz==2020.1
78
- PyYAML==5.3.1
79
- requests==2.24.0
80
- rich==5.2.1
81
- rsa==4.6
82
- ruamel.yaml==0.16.10
83
- ruamel.yaml.clib==0.2.0
84
- scikit-learn==0.23.2
85
- scipy==1.5.2
86
- shortuuid==1.0.1
87
- shtab==1.3.1
88
- six==1.15.0
89
- smmap==3.0.4
90
- spacy==2.3.2
91
- srsly==1.0.2
92
- tabulate==0.8.7
93
- thinc==7.4.1
94
- threadpoolctl==2.1.0
95
- toml==0.10.1
96
- torch==1.6.0
97
- torchvision==0.7.0
98
- tqdm==4.48.2
99
- traitlets==4.3.3
100
- typing-extensions==3.7.4.3
101
- urllib3==1.25.10
102
- voluptuous==0.11.7
103
- wasabi==0.7.1
104
- wcwidth==0.2.5
105
- wheel==0.35.1
106
- zc.lockfile==2.0
107
- zipp==3.1.0
 
1
+ dvc==1.10.1
2
+ fastai==2.1.5
3
+ torch==1.7.0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  h5py==2.10.0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  opencv-python==4.4.0.42
6
+ tqdm==4.52.0
7
+ numpy==1.19.4
8
+ scikit-learn==0.23.2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
src/code/make_dataset.py CHANGED
@@ -39,13 +39,12 @@ import os
39
  import scipy.io
40
  import sys
41
  import cv2
 
42
 
43
 
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]
@@ -75,12 +74,9 @@ if __name__ == "__main__":
75
  print("reading", sys.argv[1])
76
 
77
  images = h5_file['images']
78
- scenes = [u''.join(chr(c) for c in h5_file[obj_ref]) for obj_ref in h5_file['sceneTypes'][0]]
79
-
80
- print("processing images")
81
- for i, image in enumerate(images):
82
- print("image", i + 1, "/", len(images))
83
 
 
84
  idx = int(i) + 1
85
  if idx in train_images:
86
  train_test = "train"
@@ -93,4 +89,4 @@ if __name__ == "__main__":
93
  os.makedirs(folder)
94
  convert_image(i, scenes[i], depth[i, :, :].T, image.T, folder)
95
 
96
- print("Finished")
 
39
  import scipy.io
40
  import sys
41
  import cv2
42
+ from tqdm import tqdm
43
 
44
 
45
  def convert_image(i, scene, depth, image, folder):
46
+ # depth is given in meters (Kinect has a range of around .5m and 4.5m but can sense also at 8m)
47
+ normalized_depth = cv2.normalize(depth, None, 0, 255, cv2.NORM_MINMAX)
 
 
48
  cv2.imwrite("%s/%05d_depth.png" % (folder, i), normalized_depth)
49
 
50
  image = image[:, :, ::-1]
 
74
  print("reading", sys.argv[1])
75
 
76
  images = h5_file['images']
77
+ scenes = [u''.join(chr(c[0]) for c in h5_file[obj_ref]) for obj_ref in h5_file['sceneTypes'][0]]
 
 
 
 
78
 
79
+ for i, image in tqdm(enumerate(images), desc="processing images", total=len(images)):
80
  idx = int(i) + 1
81
  if idx in train_images:
82
  train_test = "train"
 
89
  os.makedirs(folder)
90
  convert_image(i, scenes[i], depth[i, :, :].T, image.T, folder)
91
 
92
+ print("Finished")
src/code/training.py CHANGED
@@ -1,6 +1,6 @@
1
  import torch
2
  import sys
3
- from fastai2.vision.all import *
4
  from torchvision.utils import save_image
5
 
6
  class ImageImageDataLoaders(DataLoaders):
@@ -37,7 +37,8 @@ if __name__ == "__main__":
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')
 
1
  import torch
2
  import sys
3
+ from fastai.vision.all import *
4
  from torchvision.utils import save_image
5
 
6
  class ImageImageDataLoaders(DataLoaders):
 
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/test/')
41
+ print("Training model...")
42
  learner.fine_tune(1)
43
+ print("Saving model...")
44
  learner.save('model')