MOHAMMED EL KASSOIRI commited on
Commit
db944bb
·
verified ·
1 Parent(s): 5b50e81

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +42 -37
README.md CHANGED
@@ -1,69 +1,74 @@
1
  # Waste Classification Model
2
 
3
- This is a Keras model for classifying waste into different categories. This model was trained to identify various types of waste materials to aid in recycling and waste management efforts.
4
 
5
  ## Model Details
6
 
7
- This model is a Convolutional Neural Network (CNN) built with TensorFlow/Keras.
 
 
 
8
 
9
- * **Input:** Images of waste materials. The expected input size is (128, 128) pixels with 3 color channels (RGB).
10
- * **Output:** The model outputs a prediction probability for each waste category.
11
- * **Categories:** The model is trained to classify waste into the following categories (assuming these are your categories - please adjust if different):
12
- * Cardboard
13
- * Glass
14
- * Metal
15
- * Paper
16
- * Plastic
17
- * Trash
18
 
19
- ## How to Use
 
 
 
 
 
 
20
 
21
- You can load and use this model for inference using the `tensorflow` and `huggingface_hub` libraries in Python.
22
-
23
- First, make sure you have the necessary libraries installed:
24
 
 
 
 
25
 
 
26
 
 
27
  from huggingface_hub import hf_hub_download
28
  import tensorflow as tf
29
  import numpy as np
30
  from tensorflow.keras.preprocessing import image
31
 
32
- # Replace with your model repository and filename
33
  repo_id = "MOHAMMED7M7/waste-classification-model"
34
- filename = "waste_classification_model.keras" # Make sure this is the correct filename you uploaded
35
-
36
- # Download the model file
37
  model_path = hf_hub_download(repo_id=repo_id, filename=filename)
38
-
39
- # Load the model
40
  model = tf.keras.models.load_model(model_path)
41
 
42
- print("Model loaded successfully!")
43
-
44
- # Example of making a prediction
45
- # Replace 'path/to/your/image.jpg' with the actual path to your image
46
  def preprocess_image(img_path):
47
- img = image.load_img(img_path, target_size=(128, 128)) # Ensure target_size matches your model
48
  img_array = image.img_to_array(img)
49
  img_array = np.expand_dims(img_array, axis=0)
50
- img_array /= 255.0 # Normalize the image if your model expects it
51
  return img_array
52
 
53
- # Replace with the path to your image
54
  image_path = 'path/to/your/image.jpg'
55
-
56
- # Preprocess the image
57
  processed_image = preprocess_image(image_path)
58
-
59
- # Make a prediction
60
  predictions = model.predict(processed_image)
61
 
62
- # Get the predicted class (assuming a classification model)
 
63
  predicted_class_index = np.argmax(predictions)
 
 
 
 
 
 
 
 
 
 
 
 
 
64
 
65
- # You'll need a list of your class names to map the index to a label
66
- class_names = ['cardboard', 'glass', 'metal', 'paper', 'plastic', 'trash'] # Replace with your actual class names
67
- predicted_class_label = class_names[predicted_class_index]
68
 
69
- print(f"The predicted class is: {predicted_class_label}")
 
1
  # Waste Classification Model
2
 
3
+ A Convolutional Neural Network (CNN) built with TensorFlow/Keras for automated waste classification. This model identifies and categorizes different types of waste materials to support recycling and waste management efforts.
4
 
5
  ## Model Details
6
 
7
+ - **Architecture**: Convolutional Neural Network (CNN)
8
+ - **Framework**: TensorFlow/Keras
9
+ - **Input Size**: 128×128 pixels, RGB (3 channels)
10
+ - **Categories**: 6 waste types
11
 
12
+ ### Classification Categories
 
 
 
 
 
 
 
 
13
 
14
+ The model classifies waste into these categories:
15
+ - **Cardboard**
16
+ - **Glass**
17
+ - **Metal**
18
+ - **Paper**
19
+ - **Plastic**
20
+ - **Trash**
21
 
22
+ ## Installation
 
 
23
 
24
+ ```bash
25
+ pip install tensorflow huggingface-hub numpy pillow
26
+ ```
27
 
28
+ ## Usage
29
 
30
+ ```python
31
  from huggingface_hub import hf_hub_download
32
  import tensorflow as tf
33
  import numpy as np
34
  from tensorflow.keras.preprocessing import image
35
 
36
+ # Download and load model
37
  repo_id = "MOHAMMED7M7/waste-classification-model"
38
+ filename = "waste_classification_model.keras"
 
 
39
  model_path = hf_hub_download(repo_id=repo_id, filename=filename)
 
 
40
  model = tf.keras.models.load_model(model_path)
41
 
42
+ # Preprocess image
 
 
 
43
  def preprocess_image(img_path):
44
+ img = image.load_img(img_path, target_size=(128, 128))
45
  img_array = image.img_to_array(img)
46
  img_array = np.expand_dims(img_array, axis=0)
47
+ img_array /= 255.0
48
  return img_array
49
 
50
+ # Make prediction
51
  image_path = 'path/to/your/image.jpg'
 
 
52
  processed_image = preprocess_image(image_path)
 
 
53
  predictions = model.predict(processed_image)
54
 
55
+ # Get result
56
+ class_names = ['cardboard', 'glass', 'metal', 'paper', 'plastic', 'trash']
57
  predicted_class_index = np.argmax(predictions)
58
+ predicted_class = class_names[predicted_class_index]
59
+ confidence = predictions[0][predicted_class_index]
60
+
61
+ print(f"Predicted class: {predicted_class}")
62
+ print(f"Confidence: {confidence:.2%}")
63
+ ```
64
+
65
+ ## Requirements
66
+
67
+ - Python 3.7+
68
+ - TensorFlow 2.8+
69
+ - NumPy
70
+ - Pillow
71
 
72
+ ## License
 
 
73
 
74
+ MIT License