justsomerandomdude264 commited on
Commit
c5bd7aa
1 Parent(s): e467214

Initial commit

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. README.md +64 -0
  2. confusion_matrix.png +0 -0
  3. data/test/Cardboard/Cardboard_100.jpg +0 -0
  4. data/test/Cardboard/Cardboard_106.jpg +0 -0
  5. data/test/Cardboard/Cardboard_122.jpg +0 -0
  6. data/test/Cardboard/Cardboard_126.jpg +0 -0
  7. data/test/Cardboard/Cardboard_166.jpg +0 -0
  8. data/test/Cardboard/Cardboard_188.jpg +0 -0
  9. data/test/Cardboard/Cardboard_212.jpg +0 -0
  10. data/test/Cardboard/Cardboard_227.jpg +0 -0
  11. data/test/Cardboard/Cardboard_232.jpg +0 -0
  12. data/test/Cardboard/Cardboard_246.jpg +0 -0
  13. data/test/Cardboard/Cardboard_249.jpg +0 -0
  14. data/test/Cardboard/Cardboard_265.jpg +0 -0
  15. data/test/Cardboard/Cardboard_281.jpg +0 -0
  16. data/test/Cardboard/Cardboard_29.jpg +0 -0
  17. data/test/Cardboard/Cardboard_290.jpg +0 -0
  18. data/test/Cardboard/Cardboard_294.jpg +0 -0
  19. data/test/Cardboard/Cardboard_348.jpg +0 -0
  20. data/test/Cardboard/Cardboard_354.jpg +0 -0
  21. data/test/Cardboard/Cardboard_357.jpg +0 -0
  22. data/test/Cardboard/Cardboard_38.jpg +0 -0
  23. data/test/Cardboard/Cardboard_380.jpg +0 -0
  24. data/test/Cardboard/Cardboard_381.jpg +0 -0
  25. data/test/Cardboard/Cardboard_388.jpg +0 -0
  26. data/test/Cardboard/Cardboard_430.jpg +0 -0
  27. data/test/Cardboard/Cardboard_447.jpg +0 -0
  28. data/test/Cardboard/Cardboard_54.jpg +0 -0
  29. data/test/Cardboard/Cardboard_85.jpg +0 -0
  30. data/test/Cardboard/Cardboard_90.jpg +0 -0
  31. data/test/Food Organics/Food Organics_107.jpg +0 -0
  32. data/test/Food Organics/Food Organics_126.jpg +0 -0
  33. data/test/Food Organics/Food Organics_184.jpg +0 -0
  34. data/test/Food Organics/Food Organics_208.jpg +0 -0
  35. data/test/Food Organics/Food Organics_213.jpg +0 -0
  36. data/test/Food Organics/Food Organics_221.jpg +0 -0
  37. data/test/Food Organics/Food Organics_222.jpg +0 -0
  38. data/test/Food Organics/Food Organics_254.jpg +0 -0
  39. data/test/Food Organics/Food Organics_259.jpg +0 -0
  40. data/test/Food Organics/Food Organics_264.jpg +0 -0
  41. data/test/Food Organics/Food Organics_27.jpg +0 -0
  42. data/test/Food Organics/Food Organics_280.jpg +0 -0
  43. data/test/Food Organics/Food Organics_288.jpg +0 -0
  44. data/test/Food Organics/Food Organics_291.jpg +0 -0
  45. data/test/Food Organics/Food Organics_300.jpg +0 -0
  46. data/test/Food Organics/Food Organics_327.jpg +0 -0
  47. data/test/Food Organics/Food Organics_335.jpg +0 -0
  48. data/test/Food Organics/Food Organics_354.jpg +0 -0
  49. data/test/Food Organics/Food Organics_369.jpg +0 -0
  50. data/test/Food Organics/Food Organics_374.jpg +0 -0
README.md ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ## Trash Classification CNN Model
2
+
3
+ ### What is this?
4
+
5
+ This project is a convolutional neural network (CNN) model developed for the purpose of classifying different types of trash items. The dataset used for training this model is the RealWaste electronic dataset, which is available on The UCI Machine Learning Repository. The dataset is provided by the Wollongong City Council and is licensed under CC BY 4.0.
6
+
7
+ The CNN model in this project utilizes the TinyVGG architecture, a compact version of the popular VGG neural network architecture. The model is trained to classify trash items into the following subcategories:
8
+
9
+ - Cardboard
10
+ - Food Organics
11
+ - Glass
12
+ - Metal
13
+ - Miscellaneous Trash
14
+ - Paper
15
+ - Plastic
16
+ - Textile Trash
17
+ - Vegetation
18
+
19
+ In total, there are 9 categories into which the trash items are classified.
20
+
21
+ For more details about the CNN architecture used in this project, you can refer to the [CNN Explainer](https://poloclub.github.io/cnn-explainer/) website.
22
+
23
+ ### Info
24
+
25
+ Only 30% of the data from the Real Trash Dataset has been used and divided into an 80%-20% split of Train and Test.
26
+
27
+ The Repository contains 7 files:
28
+
29
+ 1. **data_setup.py**: This file contains functions for setting up the data into datasets using ImageFolder and then turning it into batches using DataLoader. It also returns the names of the classes.
30
+
31
+ 2. **model_builder.py**: This file contains a class which subclasses nn.Module and replicates the TinyVGG CNN model architecture with a few modifications here and there.
32
+
33
+ 3. **engine.py**: This file contains three functions: `train_step`, `test_step`, and `train`. The previous two are used to train and test the model, respectively, and the last one integrates both to train the model.
34
+
35
+ 4. **plotting.py**: This file contains functions to plot metrics like loss and accuracy using `plot_metrics`, and it also has a function `plot_confusion_Matrix` to plot the confusion matrix.
36
+
37
+ 5. **predict.py**: This file can be run with `--image` and `--model_path` arguments to get the prediction of the model on the specified image path.
38
+
39
+ 6. **utils.py**: This file contains functions to save the model in a specific folder with a changeable name.
40
+
41
+ 7. **train.py**: This script uses all the files except `predict.py` and can take argument flags to change hyperparameters. It can be run with the following arguments:
42
+
43
+ ```
44
+ python train.py --train_dir TRAIN_DIR --test_dir TEST_DIR --learning_rate LEARNING_RATE --batch_size BATCH_SIZE --num_epochs NUM_EPOCHS
45
+ ```
46
+
47
+ Additionally, it is device agnostic, meaning it automatically utilizes available resources regardless of the specific device used.
48
+
49
+ Additionally, the repository contains 2 folders:
50
+
51
+ - **data**: This stores the data and has subdirectories train and test.
52
+
53
+ - **models**: This stores the model saved by utils.py.
54
+
55
+ - **samples**: This has 10 pictures, you can use for testing the model using `predict.py`.
56
+
57
+
58
+ ### What I Learned?
59
+
60
+ This project taught me the basics of **Computer Vision** with **PyTorch**, a lot about **Convolutional Neural Networks (CNNs)**, and also taught me how to **model** my project. It also taught me how to write **readable code** and handle **errors**, especially in the `predict.py` file.
61
+
62
+ I gained understanding about **classification** and how to implement it with **neural networks** and **deep learning**. While working on this, I learned the basics of **matplotlib** and **mlxtend** and also realized the impact of **data quantity** on results, which led to the decision of using only **30% of the data**.
63
+
64
+ I found that the best working **optimizer** with **TinyVGG** was an **Adam Optimizer** with a **learning rate** of **0.001**, trained on **20 epochs** and a **batch size** of **32** with **15** **hidden units**. This resulting in **Train Loss** of _**0.24**_ and **Test Loss** of _**2.17**_, **Train Accuracy** of _**91%**_ and **Test Accuracy** of _**55%**_.
confusion_matrix.png ADDED
data/test/Cardboard/Cardboard_100.jpg ADDED
data/test/Cardboard/Cardboard_106.jpg ADDED
data/test/Cardboard/Cardboard_122.jpg ADDED
data/test/Cardboard/Cardboard_126.jpg ADDED
data/test/Cardboard/Cardboard_166.jpg ADDED
data/test/Cardboard/Cardboard_188.jpg ADDED
data/test/Cardboard/Cardboard_212.jpg ADDED
data/test/Cardboard/Cardboard_227.jpg ADDED
data/test/Cardboard/Cardboard_232.jpg ADDED
data/test/Cardboard/Cardboard_246.jpg ADDED
data/test/Cardboard/Cardboard_249.jpg ADDED
data/test/Cardboard/Cardboard_265.jpg ADDED
data/test/Cardboard/Cardboard_281.jpg ADDED
data/test/Cardboard/Cardboard_29.jpg ADDED
data/test/Cardboard/Cardboard_290.jpg ADDED
data/test/Cardboard/Cardboard_294.jpg ADDED
data/test/Cardboard/Cardboard_348.jpg ADDED
data/test/Cardboard/Cardboard_354.jpg ADDED
data/test/Cardboard/Cardboard_357.jpg ADDED
data/test/Cardboard/Cardboard_38.jpg ADDED
data/test/Cardboard/Cardboard_380.jpg ADDED
data/test/Cardboard/Cardboard_381.jpg ADDED
data/test/Cardboard/Cardboard_388.jpg ADDED
data/test/Cardboard/Cardboard_430.jpg ADDED
data/test/Cardboard/Cardboard_447.jpg ADDED
data/test/Cardboard/Cardboard_54.jpg ADDED
data/test/Cardboard/Cardboard_85.jpg ADDED
data/test/Cardboard/Cardboard_90.jpg ADDED
data/test/Food Organics/Food Organics_107.jpg ADDED
data/test/Food Organics/Food Organics_126.jpg ADDED
data/test/Food Organics/Food Organics_184.jpg ADDED
data/test/Food Organics/Food Organics_208.jpg ADDED
data/test/Food Organics/Food Organics_213.jpg ADDED
data/test/Food Organics/Food Organics_221.jpg ADDED
data/test/Food Organics/Food Organics_222.jpg ADDED
data/test/Food Organics/Food Organics_254.jpg ADDED
data/test/Food Organics/Food Organics_259.jpg ADDED
data/test/Food Organics/Food Organics_264.jpg ADDED
data/test/Food Organics/Food Organics_27.jpg ADDED
data/test/Food Organics/Food Organics_280.jpg ADDED
data/test/Food Organics/Food Organics_288.jpg ADDED
data/test/Food Organics/Food Organics_291.jpg ADDED
data/test/Food Organics/Food Organics_300.jpg ADDED
data/test/Food Organics/Food Organics_327.jpg ADDED
data/test/Food Organics/Food Organics_335.jpg ADDED
data/test/Food Organics/Food Organics_354.jpg ADDED
data/test/Food Organics/Food Organics_369.jpg ADDED
data/test/Food Organics/Food Organics_374.jpg ADDED