Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
313 commits
Select commit Hold shift + click to select a range
2209dd1
seprated the the function into more logical sub files
JHZ5583233 May 12, 2025
2ca2536
multithreading implemented in the path getter
JHZ5583233 May 12, 2025
0dcf8df
multithreading implemented in the path getter
JHZ5583233 May 12, 2025
aafd641
added normality test for data visualizer
JHZ5583233 May 12, 2025
243c932
added normality test for data visualizer
JHZ5583233 May 12, 2025
d603a89
multithreading for normility test in subset maker
JHZ5583233 May 12, 2025
860ad5b
multithreading for normility test in subset maker
JHZ5583233 May 12, 2025
6f02b79
added tittle to the histogram
JHZ5583233 May 12, 2025
59bd13c
added tittle to the histogram
JHZ5583233 May 12, 2025
c835820
added multithreading and memory check
JHZ5583233 May 12, 2025
963406e
added multithreading and memory check
JHZ5583233 May 12, 2025
15e6259
flake 8 compliance hopefully
JHZ5583233 May 12, 2025
3517b01
flake 8 compliance hopefully
JHZ5583233 May 12, 2025
f2b4266
flake 8 conflict gonna resolve in main
JHZ5583233 May 12, 2025
ec70d40
flake 8 conflict gonna resolve in main
JHZ5583233 May 12, 2025
60d80b8
resolve the flake8 conflict
JHZ5583233 May 12, 2025
94259e0
resolve the flake8 conflict
JHZ5583233 May 12, 2025
207451c
Merge branch 'main' of https://github.com/JHZ5583233/Applied-ML-16
JHZ5583233 May 12, 2025
4e1ee4e
Merge branch 'main' of https://github.com/JHZ5583233/Applied-ML-16
JHZ5583233 May 12, 2025
94dfaa6
changed to proper flake 8 command
JHZ5583233 May 12, 2025
d13491e
changed to proper flake 8 command
JHZ5583233 May 12, 2025
167e71a
found bug in get train data folders. It was returning training data f…
JHZ5583233 May 12, 2025
ae29b6c
found bug in get train data folders. It was returning training data f…
JHZ5583233 May 12, 2025
5c9dbd1
found multithread bug. where matplotlib can't plot when it is on non …
JHZ5583233 May 12, 2025
1a1988c
found multithread bug. where matplotlib can't plot when it is on non …
JHZ5583233 May 12, 2025
ba321d5
fixed the matplotlib bug and now it is always drawing the plot on the…
JHZ5583233 May 13, 2025
a539a93
fixed the matplotlib bug and now it is always drawing the plot on the…
JHZ5583233 May 13, 2025
53968d6
removed workflow from branch
JHZ5583233 May 13, 2025
af3d3de
removed workflow from branch
JHZ5583233 May 13, 2025
1b5b8ef
added a todo
JHZ5583233 May 13, 2025
32550a8
added a todo
JHZ5583233 May 13, 2025
26eac84
updated the gitignore to not includer each ignore data point
JHZ5583233 May 13, 2025
04d113f
updated the gitignore to not includer each ignore data point
JHZ5583233 May 13, 2025
c649197
made it sop that you can give the function train or val to subset the…
JHZ5583233 May 14, 2025
414d2ff
made it sop that you can give the function train or val to subset the…
JHZ5583233 May 14, 2025
6aca42f
made it so that the code can generate new data selection even though …
JHZ5583233 May 14, 2025
63b3958
made it so that the code can generate new data selection even though …
JHZ5583233 May 14, 2025
2e18e20
fixed error of non given argument
JHZ5583233 May 14, 2025
fb11626
fixed error of non given argument
JHZ5583233 May 14, 2025
624b5a8
fixed? flake8 warning due to different settings
JHZ5583233 May 14, 2025
59ed267
fixed? flake8 warning due to different settings
JHZ5583233 May 14, 2025
54bc46e
made develpment envirement for conda
JHZ5583233 May 14, 2025
d10872f
made develpment envirement for conda
JHZ5583233 May 14, 2025
709b62d
Merge pull request #7 from JHZ5583233/2-data-selection-algotrithm
AndreiFoitos May 15, 2025
912abda
Merge pull request #7 from JHZ5583233/2-data-selection-algotrithm
AndreiFoitos May 15, 2025
4df3aa6
made basic linear regression as baseline
AndreiFoitos May 15, 2025
9c77c66
linear regression
AndreiFoitos May 15, 2025
0e59c1f
start of data loader class
JHZ5583233 May 15, 2025
d6ade70
start of data loader class
JHZ5583233 May 15, 2025
b6d27fa
made basic linear regression as baseline
AndreiFoitos May 15, 2025
f74b744
linear regression
AndreiFoitos May 15, 2025
207a220
Merge branch '6-implement-baseline-models' of https://github.com/JHZ5…
JHZ5583233 May 15, 2025
87e8621
made the data loader class
JHZ5583233 May 15, 2025
2dc0916
made the data loader class
JHZ5583233 May 15, 2025
fa56809
made data loader class where it gets the data from each folder in teh…
JHZ5583233 May 15, 2025
885e9b9
made data loader class where it gets the data from each folder in teh…
JHZ5583233 May 15, 2025
e75aade
flake 8
JHZ5583233 May 15, 2025
964eaba
flake 8
JHZ5583233 May 15, 2025
3fbed98
Merge pull request #9 from JHZ5583233/data-loader-class
JHZ5583233 May 15, 2025
26fc94e
Merge pull request #9 from JHZ5583233/data-loader-class
JHZ5583233 May 15, 2025
a55adb8
update to the linear reg
AndreiFoitos May 15, 2025
64a0a48
made basic linear regression as baseline
AndreiFoitos May 15, 2025
4ce9541
linear regression
AndreiFoitos May 15, 2025
28c728c
made basic linear regression as baseline
AndreiFoitos May 15, 2025
95078a1
update to the linear reg
AndreiFoitos May 15, 2025
fa5b691
added warning for some dangerours code
JHZ5583233 May 15, 2025
0447fd5
added warning for some dangerours code
JHZ5583233 May 15, 2025
21d5ee4
Merge branch '6-implement-baseline-models' of https://github.com/JHZ5…
AndreiFoitos May 15, 2025
f857739
updated read me to reflect the project more
JHZ5583233 May 15, 2025
0ba030f
updated read me to reflect the project more
JHZ5583233 May 15, 2025
c1273c2
Preprocessing_class created functions for tiling and padding, reconst…
juliastgermain May 16, 2025
b7d7deb
Preprocessing_class created functions for tiling and padding, reconst…
juliastgermain May 16, 2025
f6f36b9
Preprocessing_class test created with 11 tests looking at normalizati…
juliastgermain May 16, 2025
480bdbb
Preprocessing_class test created with 11 tests looking at normalizati…
juliastgermain May 16, 2025
51b99b3
changed some docstrings and comments, deleted what was unneeded
juliastgermain May 17, 2025
390b4ff
changed some docstrings and comments, deleted what was unneeded
juliastgermain May 17, 2025
11620c2
only test depth under 100m
JHZ5583233 May 17, 2025
2a3620b
only test depth under 100m
JHZ5583233 May 17, 2025
3f60c99
optimized the testing and plotting a bit
JHZ5583233 May 17, 2025
f735730
optimized the testing and plotting a bit
JHZ5583233 May 17, 2025
d028c24
doc strings and type hinting
JHZ5583233 May 17, 2025
22a3fac
doc strings and type hinting
JHZ5583233 May 17, 2025
5c1ca1d
removed unused imports and added return type hint
JHZ5583233 May 17, 2025
f12175c
removed unused imports and added return type hint
JHZ5583233 May 17, 2025
54b8e47
delete in blank lines and shortened lines over 79 to adhere to flake8
juliastgermain May 19, 2025
d6c5a1a
delete in blank lines and shortened lines over 79 to adhere to flake8
juliastgermain May 19, 2025
9efa121
added docstrings for each function the Preprocessing_class.py and typ…
juliastgermain May 20, 2025
25e82e7
added docstrings for each function the Preprocessing_class.py and typ…
juliastgermain May 20, 2025
605136a
Merge pull request #10 from JHZ5583233/1-preprocessing-class
JHZ5583233 May 20, 2025
69b3b8e
Merge pull request #10 from JHZ5583233/1-preprocessing-class
JHZ5583233 May 20, 2025
6c5b84e
made change to flake 8 to it doesn't test the unit tests
JHZ5583233 May 20, 2025
3d4090e
made change to flake 8 to it doesn't test the unit tests
JHZ5583233 May 20, 2025
0980d83
small missed flake 8 error
JHZ5583233 May 20, 2025
e1e0a78
small missed flake 8 error
JHZ5583233 May 20, 2025
8866d74
extra comments and doc string fopr better explanation
JHZ5583233 May 21, 2025
143753c
extra comments and doc string fopr better explanation
JHZ5583233 May 21, 2025
8bf0415
Copied over training
StanIvanov1235 May 21, 2025
78fc529
Merge pull request #11 from JHZ5583233/small-optimization-and-changes…
JHZ5583233 May 21, 2025
8be9da4
Merge pull request #11 from JHZ5583233/small-optimization-and-changes…
JHZ5583233 May 21, 2025
fca5fb6
made streamlit file and intro paragraph
JHZ5583233 May 21, 2025
03dfeeb
updated gitignore to ignore the shared data files in teh right place
JHZ5583233 May 21, 2025
525d079
updated gitignore to ignore the shared data files in teh right place
JHZ5583233 May 21, 2025
ef352e4
Merge branch 'main' of https://github.com/JHZ5583233/Applied-ML-16
JHZ5583233 May 21, 2025
b55a0df
Merge branch 'main' of https://github.com/JHZ5583233/Applied-ML-16
JHZ5583233 May 21, 2025
bce111d
made streamlit file and intro paragraph
JHZ5583233 May 21, 2025
6dfada7
Merge branch '14-streamlit-app-demo' of https://github.com/JHZ5583233…
JHZ5583233 May 21, 2025
186344b
base layout made. need to fix bug of it rerunning itself over and ove…
JHZ5583233 May 21, 2025
23eb05c
Copied over the rest of the files
StanIvanov1235 May 22, 2025
0d37a6c
Merge branch 'main' into 6-implement-baseline-models
JHZ5583233 May 22, 2025
f2eaf37
Took care of some of the flake8 errors
StanIvanov1235 May 22, 2025
d5038ad
More changes for flake8
StanIvanov1235 May 22, 2025
bde7759
Merge pull request #13 from JHZ5583233/4-training-loop
JHZ5583233 May 22, 2025
e88b34a
main back
StanIvanov1235 May 22, 2025
17e0d94
Merge pull request #16 from JHZ5583233/4-training-loop
JHZ5583233 May 22, 2025
4c07c33
working on the zoe model and also the linear regression
AndreiFoitos May 22, 2025
5e94cae
intergrated session state to fix the program keep rerunning whole code
JHZ5583233 May 22, 2025
f957dc7
fix bug of trying to get rid of old depth data when there wwas none s…
JHZ5583233 May 22, 2025
1ceb77d
made file downloadable
JHZ5583233 May 22, 2025
e9c1027
spelling
JHZ5583233 May 22, 2025
0822b98
added docstring to function
JHZ5583233 May 22, 2025
f0e90be
way to stop flake 8 to complain
JHZ5583233 May 22, 2025
0940a26
Merge branch 'main' into 14-streamlit-app-demo
JHZ5583233 May 22, 2025
6163904
base layout made. need to fix bug of it rerunning itself over and ove…
JHZ5583233 May 21, 2025
77bedfc
intergrated session state to fix the program keep rerunning whole code
JHZ5583233 May 22, 2025
c1e7698
fix bug of trying to get rid of old depth data when there wwas none s…
JHZ5583233 May 22, 2025
307a032
made file downloadable
JHZ5583233 May 22, 2025
1a99ffb
spelling
JHZ5583233 May 22, 2025
0c97bd2
added docstring to function
JHZ5583233 May 22, 2025
b77dfd5
way to stop flake 8 to complain
JHZ5583233 May 22, 2025
45fddb0
Merge branch '14-streamlit-app-demo' of https://github.com/JHZ5583233…
JHZ5583233 May 22, 2025
8536a5c
added doc strings
JHZ5583233 May 22, 2025
072c538
finished baseline models (Zoe and linear reg)
AndreiFoitos May 25, 2025
ef9c19b
style check
AndreiFoitos May 25, 2025
9fb2041
more style updates
AndreiFoitos May 25, 2025
16b37b1
Working model training and evaluation
StanIvanov1235 May 26, 2025
d8e821f
added model to git ignore
JHZ5583233 May 26, 2025
e23b751
added model loading
JHZ5583233 May 27, 2025
cffab13
fot some ouptput to show up
JHZ5583233 May 27, 2025
dbd47c9
in between flake 8 compliance
JHZ5583233 May 27, 2025
3159d3f
trained and evaluated linear reg and evaluated zoeDepth
AndreiFoitos May 27, 2025
e8c7f36
made it so it user can input tile size
JHZ5583233 May 28, 2025
1d416c0
made tile size modifieable
JHZ5583233 May 28, 2025
a6d9fa3
changed place of todo to a more proper place
JHZ5583233 May 28, 2025
4ad6ce2
added tiling
JHZ5583233 May 28, 2025
9aa450c
updated gitignore to ignore cnn model
JHZ5583233 May 28, 2025
2c9869c
updated gitignore to ignore cnn model
JHZ5583233 May 28, 2025
a145365
Merge branch 'update-read-me' of https://github.com/JHZ5583233/Applie…
JHZ5583233 May 28, 2025
3452a13
updated package list
JHZ5583233 May 28, 2025
3587d08
updated read me
JHZ5583233 May 28, 2025
3ae072f
added docstring to main function
JHZ5583233 May 28, 2025
5b1aa5f
updated read me to add section of train and validate
JHZ5583233 May 28, 2025
f7e78cf
replaces pip files in map to conda req file
JHZ5583233 May 28, 2025
969684d
updated repo map
JHZ5583233 May 28, 2025
bec6851
created API and added function for image to nump and numpy to torch i…
juliastgermain May 28, 2025
cac60a7
added some more steps in setup
JHZ5583233 May 28, 2025
6209618
added train and validate command and extra needed step in general set up
JHZ5583233 May 28, 2025
dee8559
got rid of temp files
JHZ5583233 May 28, 2025
43497e1
updated repo map
JHZ5583233 May 28, 2025
617ecb0
updated gitignore
JHZ5583233 May 28, 2025
1c09c1a
spelling correction
JHZ5583233 May 28, 2025
27dda2c
added init to make importing possible
JHZ5583233 May 28, 2025
9ebd78b
changed temp to a test
JHZ5583233 May 28, 2025
8534dac
docstring to main
JHZ5583233 May 28, 2025
9a4d312
flake 8
JHZ5583233 May 28, 2025
94258ad
updated package list
JHZ5583233 May 28, 2025
14933b9
added instructions for how to get data
JHZ5583233 May 28, 2025
ea6f576
changed naming in the getting started
JHZ5583233 May 28, 2025
f187b3d
removed example text
JHZ5583233 May 28, 2025
d23d9da
update requirement file
JHZ5583233 May 28, 2025
b2bda96
removed pip only packages and instructed to install torch separately
JHZ5583233 May 28, 2025
2248218
Merge pull request #18 from JHZ5583233/integration-test-branch
JHZ5583233 May 28, 2025
4ad7095
added instruction on where to place data
JHZ5583233 May 28, 2025
615dd35
flake 8
JHZ5583233 May 28, 2025
9503b15
Merge branch 'main' of https://github.com/JHZ5583233/Applied-ML-16
JHZ5583233 May 28, 2025
602b02b
added model to ignore and flake 8
JHZ5583233 May 28, 2025
70bfc34
updated package list
JHZ5583233 May 28, 2025
13162dc
updated read me
JHZ5583233 May 28, 2025
d4281dd
updated read me to add section of train and validate
JHZ5583233 May 28, 2025
0389cf9
replaces pip files in map to conda req file
JHZ5583233 May 28, 2025
7b546f0
updated repo map
JHZ5583233 May 28, 2025
fd87309
added some more steps in setup
JHZ5583233 May 28, 2025
3256162
added train and validate command and extra needed step in general set up
JHZ5583233 May 28, 2025
239e106
got rid of temp files
JHZ5583233 May 28, 2025
f85ff0d
updated repo map
JHZ5583233 May 28, 2025
80c82f0
updated package list
JHZ5583233 May 28, 2025
3ce0217
added instructions for how to get data
JHZ5583233 May 28, 2025
cb6e957
changed naming in the getting started
JHZ5583233 May 28, 2025
9fd2260
removed example text
JHZ5583233 May 28, 2025
444f36c
update requirement file
JHZ5583233 May 28, 2025
c86cf64
removed pip only packages and instructed to install torch separately
JHZ5583233 May 28, 2025
7d7b699
added instruction on where to place data
JHZ5583233 May 28, 2025
3b1e020
Merge branch 'update-read-me' of https://github.com/JHZ5583233/Applie…
JHZ5583233 May 28, 2025
4e636ce
added model to repo map
JHZ5583233 May 28, 2025
acfd2ab
reformat train and validate
JHZ5583233 May 28, 2025
b34487a
made command properly formatted
JHZ5583233 May 28, 2025
04fcdd8
updated package list
JHZ5583233 May 28, 2025
f3f02cb
added docstring to main function
JHZ5583233 May 28, 2025
7124ebe
updated read me to add section of train and validate
JHZ5583233 May 28, 2025
4c52e93
added train and validate command and extra needed step in general set up
JHZ5583233 May 28, 2025
ecc3c75
updated package list
JHZ5583233 May 28, 2025
ca98fca
update requirement file
JHZ5583233 May 28, 2025
e721e0b
removed pip only packages and instructed to install torch separately
JHZ5583233 May 28, 2025
2389473
added model to repo map
JHZ5583233 May 28, 2025
439c2a5
reformat train and validate
JHZ5583233 May 28, 2025
ba0c9be
made command properly formatted
JHZ5583233 May 28, 2025
f7dc52e
Merge branch 'update-read-me' of https://github.com/JHZ5583233/Applie…
JHZ5583233 May 28, 2025
59141ed
spelling mistake
JHZ5583233 May 28, 2025
adf0498
Merge branch 'main' into data-unit-test
JHZ5583233 May 29, 2025
20d5515
Merge branch 'main' into 14-streamlit-app-demo
JHZ5583233 May 29, 2025
48bca95
altered load image function in Preprocessing_class.py to accecpt Byte…
juliastgermain May 29, 2025
6daa8de
Update README.md
juliastgermain May 29, 2025
d58a52b
reconstructed the API file a bit so that there is a specific function…
juliastgermain May 29, 2025
6c13a03
Merge pull request #17 from JHZ5583233/14-streamlit-app-demo
juliastgermain May 29, 2025
b4d34f5
Merge pull request #19 from JHZ5583233/update-read-me
juliastgermain May 29, 2025
6e581b3
changes for flake8
juliastgermain May 29, 2025
1d06479
small correction to read me
JHZ5583233 May 29, 2025
a431207
Merge pull request #20 from JHZ5583233/data-unit-test
JHZ5583233 May 29, 2025
f1e67ae
import fixes
JHZ5583233 May 29, 2025
7b064d1
properly added tiling
JHZ5583233 May 29, 2025
f7baad4
updated preprocessing class to newer version
JHZ5583233 May 29, 2025
f13fea6
made the model work
JHZ5583233 May 29, 2025
8b86099
Merge pull request #23 from JHZ5583233/14-streamlit-app-demo
JHZ5583233 May 29, 2025
786d326
flake 8
JHZ5583233 May 29, 2025
7d34642
import fixes
JHZ5583233 May 29, 2025
1d2672e
flake 8
JHZ5583233 May 29, 2025
e9c5596
Merge branch 'import-fixes' of https://github.com/JHZ5583233/Applied-…
JHZ5583233 May 29, 2025
b50a524
little extra in commant to make command fully complete
JHZ5583233 May 29, 2025
1ba440a
fixed to have it be able to train
JHZ5583233 May 29, 2025
3a15459
Merge pull request #22 from JHZ5583233/import-fixes
JHZ5583233 May 29, 2025
ba1679e
Merge branch 'main' into 12-fastapi
JHZ5583233 May 29, 2025
a311d29
changes for flake8
juliastgermain May 29, 2025
7a0da86
Merge remote-tracking branch 'origin/12-fastapi' into 12-fastapi
juliastgermain May 29, 2025
2dedb0c
added more evaluation metrics
AndreiFoitos May 29, 2025
b30e20f
read me typo and flake 8 in fast api file
JHZ5583233 May 29, 2025
407e9c5
flake 8
JHZ5583233 May 29, 2025
c5c630e
Merge pull request #21 from JHZ5583233/12-fastapi
JHZ5583233 May 29, 2025
b0301d9
removed random qoute
JHZ5583233 May 30, 2025
d830580
changes in gitignore
AndreiFoitos May 30, 2025
1afac0e
added linear reg model to gitignore
AndreiFoitos May 30, 2025
b0f745e
Merge branch 'main' into 6-implement-baseline-models
JHZ5583233 Jun 15, 2025
1af11b6
style check
JHZ5583233 Jun 15, 2025
2c5dd3c
pep 8
JHZ5583233 Jun 15, 2025
4f58e82
pep8
JHZ5583233 Jun 15, 2025
1c635c4
pep8 eval
JHZ5583233 Jun 15, 2025
f6d4737
pep8 eval
JHZ5583233 Jun 15, 2025
8334811
pep8 zoe main
JHZ5583233 Jun 15, 2025
bbf76be
pep8 dataloader linear model
JHZ5583233 Jun 15, 2025
1bdd5e4
pep main linear
JHZ5583233 Jun 15, 2025
3bf6847
pep8 main linear
JHZ5583233 Jun 15, 2025
469e4be
pep main linear
JHZ5583233 Jun 15, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions .github/workflows/style.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Style check

on:
push:
branches:
- main
- master

pull_request:
branches:
- main
- master

jobs:
flake8_py3:
permissions: write-all
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- uses: actions/setup-python@v5
with:
python-version: "3.10"

- name: Install flake8 and plugins
run: |
pip install flake8 flake8-docstrings flake8-annotations

- name: Configure Flake8
run: |
echo "[flake8]" > .flake8
echo "extend-ignore = E402,W504" >> .flake8
echo "exclude = .github,autoop/tests,tests/" >> .flake8
# exclude A101, A102, D100 and everything that starts with D2 and D4
echo "ignore = ANN101,ANN102,D100,D2,D4,ANN002,ANN003" >> .flake8

- name: Run flake8
uses: suo/flake8-github-action@releases/v1
with:
checkName: "flake8_py3"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
18 changes: 16 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
Pipfile.lock
.idea
.DS_Store
.env
.vscode/
Pipfile.lock
__pycache__/
.DS_Store
venv/
.env
project_name/data/full_data/
project_name/data/subset_data/
project_name/data/val/
project_name/data/train/
project_name/data/train_subset/
project_name/data/__pycache__/
project_name/data/val_subset/
project_name/data/train_subset.7z
project_name/data/val_subset.7z
cnn_best.pth
project_name/trained_linear_model.pkl
/zoedepth/
14 changes: 0 additions & 14 deletions .pre-commit-config.yaml

This file was deleted.

89 changes: 89 additions & 0 deletions FastAPI.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import io
import torch

from fastapi import FastAPI, File, UploadFile, HTTPException
from fastapi.responses import StreamingResponse
from PIL import Image
from project_name.models.cnn import CNNBackbone
from project_name.models.Preprocessing_class import Preprocessing
from numpy import array


app = FastAPI(title="Depth Prediction API",
description="Uploads an image and "
"returns a predicted depth map.")

# Setup
MODEL_PATH = "cnn_best.pth"
model = CNNBackbone(pretrained=False)
model.load_state_dict(torch.load(MODEL_PATH, map_location="cpu"))
model.eval()
preprocessor = Preprocessing(tile_size=(256, 256))


def process_image(file_bytes: bytes,
model: torch.nn.Module,
preprocessor: Preprocessing) -> io.BytesIO:
"""Function to process image

Args:
file_bytes (bytes): file in byte representation
model (torch.nn.Module): neural network model
preprocessor (Preprocessing): preprocessing class

Returns:
bytes: depth image in byte format
"""
img_array = preprocessor.load_image(io.BytesIO(file_bytes))
tiles = preprocessor.tile_with_padding(img_array)
depth_tiles = []

for tile in tiles:
input_tensor = preprocessor.to_tensor(tile).unsqueeze(0)
with torch.no_grad():
output = model(input_tensor)
depth_tiles.append(output.squeeze().cpu().numpy())

depth_map = preprocessor.reconstruct_depth(array(depth_tiles))
depth_rgb = preprocessor.depth_to_rgb(depth_map, invert=True)

result_image = Image.fromarray(depth_rgb)
byte_io = io.BytesIO()
result_image.save(byte_io, format="PNG")
byte_io.seek(0)
return byte_io


@app.post("/predict_depth/", summary="Predict depth from image")
async def predict_depth(file: UploadFile = File(...)) -> StreamingResponse:
"""Function to generate depth from image given

Args:
file (UploadFile, optional): image file that is uploaded.
Defaults to File(...).

Raises:
HTTPException: image format is not supported
HTTPException: when there is an error processing the image

Returns:
StreamingResponse: response with processed image
"""
if not file.content_type.startswith("image/"):
raise HTTPException(status_code=400, detail="Invalid image format")
try:
contents = await file.read()
image_bytes = process_image(contents, model, preprocessor)
return StreamingResponse(image_bytes, media_type="image/png")
except Exception:
raise HTTPException(status_code=500, detail="Error processing image.")


@app.get("/", summary="Health check")
def read_root() -> dict:
"""Health check function

Returns:
dict: dict of the status
"""
return {"status": "healthy"}
158 changes: 70 additions & 88 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,77 +1,68 @@
# Applied ML Template 🛠️
# Applied ML Team 16

**Welcome to Applied Machine Learning!** This template is designed to streamline the development process and boost the quality of your code.
Welcome to our repo for our project for Applied machine learning project.

Before getting started with your projects, we encourage you to carefully read the sections below and familiarise yourselves with the proposed tools.
Our project is to train an model to approximate depth data from RGB images in a tilling pattern.

## Prerequisites
Make sure you have the following software and tools installed:

- **PyCharm**: We recommend using PyCharm as your IDE, since it offers a highly tailored experience for Python development. You can get a free student license [here](https://www.jetbrains.com/community/education/#students/).

- **Pipenv**: Pipenv is used for dependency management. This tools enables users to easily create and manage virtual environments. To install Pipenv, use the following command:
```bash
$ pip install --user pipenv
```
For detailed installation instructions, [click here](https://pipenv.pypa.io/en/latest/installation.html).

- **Git LFS**: Instead of committing large files to your repository, you should store and manage them using Git LFS. For installation information, [click here](https://github.com/git-lfs/git-lfs?utm_source=gitlfs_site&utm_medium=installation_link&utm_campaign=gitlfs#installing).
- **Conda**: Conda is used for dependency management. This tools is a standard for a lot of machine learning libraries and has support for pip packages as well. "conda install --yes --file conda_requirements.txt"
- **python 3.11**: a tested version of python that this repository works in.

## Getting Started
### Setting up your own repository
1. Fork this repository.
2. Clone your fork locally.
3. Configure a remote pointing to the upstream repository to sync changes between your fork and the original repository.
```bash
git remote add upstream https://github.com/ivopascal/Applied-ML-Template
```
**Don't skip this step.** We might update the original repository, so you should be able to easily pull our changes.

To update your forked repo follow these steps:
1. `git fetch upstream`
2. `git rebase upstream/main`
3. `git push origin main`

Sometimes you may need to use `git push --force origin main`. Only use this flag the first time you push after you rebased, and be careful as you might overwrite your teammates' changes.
### Git LFS
1. Set it up for your user account (only once, not each time you want to use it).
```bash
git lfs install
```
2. Select the files that Git LFS should manage. To track all files of a certain type, you can use a wildcard as in the command below.
```bash
git lfs track "*.psd"
```
3. Add _.gitattributes_ to the staging area.
```bash
git add .gitattributes
```
That's all, you can commit and push as always. The tracked files will be automatically stored with Git LFS.

### Pipenv
This tool is incredibly easy to use. Let's **install** our first package, which you will all need in your projects.

### general
1. Clone this repository.
2. Get the training and validation data and place in the data folder in the project_name folder.
* Data used to train our model
1. download from google drive. [drive](https://drive.google.com/drive/folders/1k_WsVOjaULgb3N2JebxjTVqJjVsw85dP)
* original data
1. download from original data. [website](https://diode-dataset.org/)
2. run subset_maker.py with amount sample and "val or "train" to get workable data folder.
3. Create conda environment with python 3.11
4. Install the packages from "conda_requirements.txt" using the command under.
```bash
pipenv install pre-commit
conda install --yes --file conda_requirements.txt
```
5. Install pytorch using the command from their [website](https://pytorch.org/).
6. Download the model from the release page and place it in the root folder of the repository

After running this command, you will notice that two files were created, namely, _Pipfile_ and _Pipfile.lock_. _Pipfile_ is the configuration file that specifies all the dependencies in your virtual environment.
### Train and validate
Both the commands below should be ran in the root folder of the repository

To **uninstall** a package, you can run the command:
* #### Train
```bash
pipenv uninstall <package-name>
python main.py --epochs (amount epoch) --batch-size (batch size) --lr (learning rate) --freeze (amount before freeze) cnn
```

To **activate** the virtual environment, run `pipenv shell`. You can now use the environment as you wish. To **deactivate** the environment run the command `exit`.
* #### Validate
```bash
python main.py evaluate (model file name with extension) --batch-size (batch size)
```

If you **already have access to a Pipfile**, you can install the dependencies using `pipenv install`.
### API
1. Run the following command in the root directory of the repository.
```bash
uvicorn FastAPI:app --reload
```
2. In a new tab in the terminal, run the following, replacing image_path.jpg with the path and file name for the input image:
```
curl -X 'POST' \
'http://127.0.0.1:8000/predict_depth/' \
-H 'accept: application/json' \
-H 'Content-Type: multipart/form-data' \
-F 'file=@image_path.jpg;type=image/jpeg'
-- output output.png
```

For a comprehensive list of commands, consult the [official documentation](https://pipenv.pypa.io/en/latest/cli.html).
### Streamlit
1. Run the following command in the root directory of the repository.
```bash
streamlit run streamlit_main.py" when in the main folder of repository.
```
2. Follow instruction on the web demo.

### Unit testing
You are expected to test your code using unit testing, which is a technique where small individual components of your code are tested in isolation.

An **example** is given in _tests/test_main.py_, which uses the standard _unittest_ Python module to test whether the function _hello_world_ from _main.py_ works as expected.

To run all the tests developed using _unittest_, simply use:
```bash
Expand All @@ -82,45 +73,36 @@ If you wish to see additional details, run it in verbose mode:
python -m unittest discover -v tests
```

### Pre-commit
Another good coding practice is using pre-commit hooks. This is used to inspect the code before committing to ensure it matches your standards.

In this course, we will be using two hooks (already configured in _.pre-commit-config.yaml_):
- Unit testing
- Flake8 (checks your code for errors, styling issues and complexity)

Since we have already configured the hooks, all you need to do is run:
repository map:
```bash
pre-commit install
```
Now `pre-commit` will automatically run whenever you want to commit something to the repository.

## Get Coding
You are now ready to start working on your projects.

We recommend following the same folder structure as in the original repository. This will make it easier for you to have cleaner and consistent code, and easier for us to follow your progress and help you.

Your repository should look something like this:
```bash
├───data # Stores .csv
├───models # Stores .pkl
├───notebooks # Contains experimental .ipynbs
├───.github
│ └────workflows
│ └──── style.yml
├───project_name
│ ├───data # For data processing, not storing .csv
│ ├───features
│ └───models # For model creation, not storing .pkl
├───reports
│ ├───data
│ │ ├───val_subset # only there when validating
│ │ ├───train_subset # only there when training
│ │ ├───data_loader.py
│ │ ├───data_test.py
│ │ ├───path_grapper.py
│ │ └───subset_maker.py
│ ├───models
│ │ ├───cnn.py
│ │ └───Preprocessing_class.py
│ └───Training
│ ├───Evaluation
│ │ ├───evaluate.py
│ │ └───validation.py
│ └───model_trainer.py
├───tests
│ ├───data
│ ├───features
│ └───models
├───.gitignore
├───.pre-commit-config.yaml
├───cnn_best.pth # download from release page
├───main.py
├───train_model.py
├───Pipfile
├───Pipfile.lock
───README.md
├───streamlit_main.py
├───FastAPI.py
├───conda_requirements.txt
───README.md
```

**Good luck and happy coding! 🚀**
Binary file added cnn_best.pth
Binary file not shown.
Binary file added conda_requirements.txt
Binary file not shown.
Loading