AI-Powered Apple Weight Estimation and Quality Grading System with Disease Detection
Back to ProjectFollow these step-by-step instructions to set up and run the AI-Powered Apple Weight Estimation and Quality Grading System on your local machine.
Download the complete project package from CodeAj Marketplace and extract it to your preferred directory. Navigate to the project root folder using terminal or command prompt.
cd path/to/apple-weight-estimation
Creating a virtual environment ensures that project dependencies do not conflict with other Python projects on your system.
python -m venv venv
venv\Scripts\activate
python3 -m venv venv
source venv/bin/activate
After activation, you should see (venv) prefix in your terminal prompt.
Install all necessary Python packages using the requirements.txt file included in the project.
pip install -r requirements.txt
This command will install the following packages:
Installation may take 5-10 minutes depending on your internet connection speed.
The project requires the Fruits-360 dataset and apple quality CSV file.
Ensure your project directory has the following structure:
apple-weight-estimation/
├── Dataset/
│ ├── apple_quality.csv
│ └── fruits-360-original-size/
│ └── (apple image folders)
├── feature_extraction.py
├── boruta_feature_selection.py
├── rfe_feature_selection.py
├── rf_importance_feature_selection.py
├── compare_feature_selection.py
├── train_final_models.py
├── app.py
├── templates/
│ └── index.html
├── static/
│ ├── css/
│ │ └── style.css
│ └── js/
│ └── main.js
└── requirements.txt
Extract features from images and CSV data to create the training dataset.
python feature_extraction.py
When prompted, press Enter to accept default settings. This process will:
This step may take 10-15 minutes depending on dataset size and system performance.
Run three different feature selection methods to identify the most relevant features for prediction.
python boruta_feature_selection.py
Press Enter for default settings. This creates results/boruta/ directory with selection reports and visualizations.
python rfe_feature_selection.py
Press Enter for default settings. This creates results/rfe/ directory with selection reports and visualizations.
python rf_importance_feature_selection.py
Press Enter for default settings. This creates results/rf_importance/ directory with selection reports and visualizations.
Each method generates:
Analyze and compare the performance of all three feature selection methods.
python compare_feature_selection.py
Press Enter for default settings. This generates:
Train the final models using the best performing feature selection method and export for deployment.
python train_final_models.py
Press Enter for default settings. This creates the models/ directory containing:
Launch the Flask web server to access the prediction interface.
python app.py
You should see output similar to:
* Running on http://127.0.0.1:5000
* Running on http://localhost:5000
Press CTRL+C to quit
Open your web browser and navigate to: http://localhost:5000
The system exposes the following REST API endpoints for programmatic access:
POST /predict
Content-Type: multipart/form-data
Body: image file
Response: JSON with predictions and metrics
POST /predict/camera
Content-Type: application/json
Body: {"image": "base64_encoded_image_data"}
Response: JSON with predictions and metrics
GET /health
Response: {"status": "healthy", "uptime": "..."}
GET /model/info
Response: Model version, metrics, and configuration
Solution: Upgrade pip to the latest version
python -m pip install --upgrade pip
Solution: Install the headless version of OpenCV
pip install opencv-python-headless
Solution: Modify the port number in app.py
# Change the last line in app.py from:
app.run(debug=True)
# To:
app.run(debug=True, port=5001)
Solution: Ensure stable internet connection and sufficient disk space. Try using a download manager for large files.
Solution: Clear browser cache, try a different browser, or restart the Flask server.
Solution: Close unnecessary applications to free up RAM, or reduce the dataset size for testing purposes.
Solution: This is normal for large datasets. The process can be monitored by checking the console output. Consider using a subset of images for initial testing.
Solution: Ensure Step 9 (train_final_models.py) completed successfully and models/ directory exists with all required files.
Edit the split ratios in training scripts by modifying the SPLIT_RATIOS variable:
SPLIT_RATIOS = [0.8, 0.7, 0.6] # Change to desired ratios
Modify hyperparameters in the model training sections of each script. For example, in Random Forest:
RandomForestRegressor(
n_estimators=200, # Increase for better accuracy
max_depth=20, # Adjust tree depth
random_state=42
)
Edit the following files to change appearance:
Extend feature_extraction.py to include additional image processing or data features:
# Add in feature_extraction.py
def extract_new_feature(image):
# Your custom feature extraction logic
return feature_value
Follow the existing model structure to add new algorithms like SVM, Neural Networks, or Gradient Boosting variants.
If you encounter any issues during installation or have questions about the project:
Before proceeding, ensure the following:
Congratulations! Your AI-Powered Apple Weight Estimation and Quality Grading System is now ready to use.
Our team is here to assist you with installation and setup.