vishal-adithya commited on
Commit
98ff808
·
verified ·
1 Parent(s): 95a642c

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +25 -36
README.md CHANGED
@@ -20,7 +20,21 @@ tags:
20
 
21
  ## Overview
22
  This project demonstrates a depth estimation model that predicts the average depth of images using features extracted from a pre-trained ResNet50 model and an XGBoost regressor. The model was trained using the **NYUv2 dataset** hosted on Hugging Face ([0jl/NYUv2](https://huggingface.co/datasets/0jl/NYUv2)). The trained model is saved as `model.pkl` using Python's `pickle` library for easy deployment and reuse.
 
 
 
 
 
23
 
 
 
 
 
 
 
 
 
 
24
  ## Features
25
  - **Model Architecture**:
26
  - Feature extraction: ResNet50 (pre-trained on ImageNet, with the top layers removed and global average pooling).
@@ -41,47 +55,33 @@ This project demonstrates a depth estimation model that predicts the average dep
41
  - Preprocessing: Images were normalized using the `preprocess_input` function from TensorFlow's ResNet50 module.
42
  2. **Regression**:
43
  - XGBoost regressor was trained on the extracted features to predict average depth values.
44
- - Hyperparameters were tuned using cross-validation for optimal performance.
45
 
46
  ## Results
47
- - **R² Score**: 0.741 (indicates the model explains 74.1% of the variance in depth prediction).
48
- - Performance is reasonable for a first implementation and can be further improved with additional tuning or feature extraction methods.
49
 
50
  ## How to Use
51
  ### Requirements
52
  1. Python 3.8+
53
  2. Required libraries:
54
  - `numpy`
55
- - `tensorflow`
56
- - `xgboost`
57
  - `pickle`
58
- - `opencv-python`
59
  - `datasets`
 
 
 
 
60
 
61
  Install the dependencies using pip:
62
  ```bash
63
- pip install numpy tensorflow xgboost pickle-mixin opencv-python datasets
64
- ```
65
-
66
- ### Loading the Model
67
- The model is saved as `model.pkl` using `pickle`. You can load and use it as follows:
68
-
69
- ```python
70
- import pickle
71
-
72
- # Load the trained model
73
- with open("model.pkl", "rb") as f:
74
- model = pickle.load(f)
75
-
76
- # Example usage
77
- features = extract_features("path/to/image.jpg") # Use the same feature extraction pipeline
78
- predicted_depth = model.predict([features])
79
- print("Predicted Depth:", predicted_depth[0])
80
  ```
81
 
82
  ### Training Pipeline
83
  If you want to retrain the model, follow these steps:
84
- NOTE: This pipline has just the overlook and the basic parameters more additional parameter tunings and preprocessing steps were being conducted during the training of the original model
85
  1. Download the **NYUv2 dataset** from Hugging Face:
86
  ```python
87
  from datasets import load_dataset
@@ -89,38 +89,27 @@ NOTE: This pipline has just the overlook and the basic parameters more additiona
89
  ```
90
  2. Extract features using ResNet50:
91
  ```python
92
- from tensorflow.keras.applications import ResNet50
93
- from tensorflow.keras.applications.resnet50 import preprocess_input
94
- import numpy as np
95
 
96
- # Load ResNet50 model
97
  model = ResNet50(weights="imagenet", include_top=False, pooling="avg")
98
 
99
  from PIL import Image
100
  def extract_features(image_path):
101
- image = image.resize((224, 224))
102
- image_array = np.array(image)
103
- image_array = np.expand_dims(image_array, axis=0).astype("float32")
104
  image_array = preprocess_input(image_array)
105
-
106
  features = model.predict(image_array)
107
  return features.flatten()
108
  ```
109
  3. Train the XGBoost regressor on the extracted features and save the model:
110
  ```python
111
- from xgboost import XGBRegressor
112
- import pickle
113
 
114
  regressor = XGBRegressor()
115
  regressor.fit(X_train, y_train)
116
 
117
- # Save the trained model
118
  with open("model.pkl", "wb") as f:
119
  pickle.dump(regressor, f)
120
  ```
121
 
122
  ## License
123
- This project is licensed under the Apache License 2.0. See the [LICENSE](LICENSE) file for more information.
124
 
125
  ## Author
126
  **Vishal Adithya.A**
 
20
 
21
  ## Overview
22
  This project demonstrates a depth estimation model that predicts the average depth of images using features extracted from a pre-trained ResNet50 model and an XGBoost regressor. The model was trained using the **NYUv2 dataset** hosted on Hugging Face ([0jl/NYUv2](https://huggingface.co/datasets/0jl/NYUv2)). The trained model is saved as `model.pkl` using Python's `pickle` library for easy deployment and reuse.
23
+ ### Loading the Model
24
+ The model is saved as `model.pkl` using `pickle`. You can load and use it as follows:
25
+
26
+ ```python
27
+ import pickle
28
 
29
+ # Load the trained model
30
+ with open("model.pkl", "rb") as f:
31
+ model = pickle.load(f)
32
+
33
+ # Example usage
34
+ features = extract_features("path/to/image.jpg") # Use the same feature extraction pipeline
35
+ predicted_depth = model.predict([features])
36
+ print("Predicted Depth:", predicted_depth[0])
37
+ ```
38
  ## Features
39
  - **Model Architecture**:
40
  - Feature extraction: ResNet50 (pre-trained on ImageNet, with the top layers removed and global average pooling).
 
55
  - Preprocessing: Images were normalized using the `preprocess_input` function from TensorFlow's ResNet50 module.
56
  2. **Regression**:
57
  - XGBoost regressor was trained on the extracted features to predict average depth values.
58
+ - Hyperparameters were tuned using cross-validation techniques for optimal performance.
59
 
60
  ## Results
61
+ - **R² Score**: 0.841.
62
+ - Performance is reasonable for a first few implementation and can be further improved with additional tuning or by improving feature extraction methods.
63
 
64
  ## How to Use
65
  ### Requirements
66
  1. Python 3.8+
67
  2. Required libraries:
68
  - `numpy`
 
 
69
  - `pickle`
70
+ - `xgboost`
71
  - `datasets`
72
+ - `tensorflow`
73
+ - 'scikit-learn'
74
+ - `opencv-python`
75
+
76
 
77
  Install the dependencies using pip:
78
  ```bash
79
+ pip install numpy tensorflow xgboost pickle-mixin opencv-python datasets scikit-learn
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
80
  ```
81
 
82
  ### Training Pipeline
83
  If you want to retrain the model, follow these steps:
84
+ NOTE: This pipeline has just the base fundamental code more additional parameter tunings and preprocessing steps were being conducted during the training of the original model
85
  1. Download the **NYUv2 dataset** from Hugging Face:
86
  ```python
87
  from datasets import load_dataset
 
89
  ```
90
  2. Extract features using ResNet50:
91
  ```python
 
 
 
92
 
 
93
  model = ResNet50(weights="imagenet", include_top=False, pooling="avg")
94
 
95
  from PIL import Image
96
  def extract_features(image_path):
 
 
 
97
  image_array = preprocess_input(image_array)
 
98
  features = model.predict(image_array)
99
  return features.flatten()
100
  ```
101
  3. Train the XGBoost regressor on the extracted features and save the model:
102
  ```python
 
 
103
 
104
  regressor = XGBRegressor()
105
  regressor.fit(X_train, y_train)
106
 
 
107
  with open("model.pkl", "wb") as f:
108
  pickle.dump(regressor, f)
109
  ```
110
 
111
  ## License
112
+ This project is licensed under the Apache License 2.0.
113
 
114
  ## Author
115
  **Vishal Adithya.A**