Documentation

Installation Guide

AI-Powered Apple Weight Estimation and Quality Grading System with Disease Detection

Step-by-step Setup Verified Instructions Chat Support
Back to Project
Complete Guide

Installation and Setup Guide

Follow these step-by-step instructions to set up and run the AI-Powered Apple Weight Estimation and Quality Grading System on your local machine.

System Requirements

  • Python 3.8 or higher
  • pip package manager
  • Minimum 4GB RAM
  • 2GB free disk space
  • Modern web browser (Chrome, Firefox, Safari, Edge)
  • Operating System: Windows 10/11, Linux, or MacOS

Step 1: Download Project Files

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
    

Step 2: Create Virtual Environment (Recommended)

Creating a virtual environment ensures that project dependencies do not conflict with other Python projects on your system.

For Windows:

python -m venv venv
venv\Scripts\activate
    

For Linux/Mac:

python3 -m venv venv
source venv/bin/activate
    

After activation, you should see (venv) prefix in your terminal prompt.

Step 3: Install Required Dependencies

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:

  • Flask - Web framework for backend server
  • scikit-learn - Machine learning library
  • XGBoost - Gradient boosting framework
  • OpenCV (opencv-python) - Computer vision library
  • NumPy - Numerical computing library
  • Pandas - Data manipulation and analysis
  • Matplotlib - Data visualization
  • Seaborn - Statistical data visualization
  • Pillow - Image processing library
  • Boruta - Feature selection library

Installation may take 5-10 minutes depending on your internet connection speed.

Step 4: Download Dataset

The project requires the Fruits-360 dataset and apple quality CSV file.

  1. Download the dataset from the provided Google Drive link: Download Dataset
  2. Extract the downloaded ZIP file
  3. Create a folder named Dataset in the project root directory
  4. Move the extracted contents into the Dataset folder

Step 5: Verify Dataset Structure

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
    

Step 6: Run Feature Extraction

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:

  • Process all apple images from the dataset
  • Extract color histograms, texture features, and morphological characteristics
  • Combine image features with CSV quality data
  • Generate features.csv file in the project root

This step may take 10-15 minutes depending on dataset size and system performance.

Step 7: Perform Feature Selection

Run three different feature selection methods to identify the most relevant features for prediction.

7.1 Boruta Feature Selection

python boruta_feature_selection.py
    

Press Enter for default settings. This creates results/boruta/ directory with selection reports and visualizations.

7.2 RFE (Recursive Feature Elimination)

python rfe_feature_selection.py
    

Press Enter for default settings. This creates results/rfe/ directory with selection reports and visualizations.

7.3 Random Forest Importance

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:

  • Feature selection report (CSV)
  • Overall summary with metrics
  • Per-split results for 80-20, 70-30, 60-40 ratios
  • Prediction CSVs for each model
  • Feature importance charts (PNG)
  • Actual vs Predicted plots (PNG)
  • Residual analysis plots (PNG)
  • Model comparison charts (PNG)
  • Correlation heatmaps (PNG)

Step 8: Compare Feature Selection Methods

Analyze and compare the performance of all three feature selection methods.

python compare_feature_selection.py
    

Press Enter for default settings. This generates:

  • Comprehensive comparison report in results/comparison/
  • Performance metrics for each method
  • Recommended feature selection approach
  • Comparative visualizations

Step 9: Train Final Production Models

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:

  • weight_model.pkl - Trained regression model for weight prediction
  • quality_model.pkl - Trained classifier for quality grading
  • disease_model.pkl - Trained classifier for disease detection
  • scaler.pkl - Feature scaler for input normalization
  • selected_features.json - List of selected features
  • model_config.json - Model configuration and metadata

Step 10: Start Web Application

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

Using the Application

  1. Upload Image: Click the file upload button and select an apple image from your computer
  2. Camera Capture: Alternatively, click the camera button to capture an image directly
  3. Get Predictions: Click the "Predict" button to process the image
  4. View Results: The system will display:
    • Predicted weight in grams
    • Quality classification (Fresh, Average, or Bad)
    • Disease detection results (Scab, Bitter Rot, Sooty Blotch & Flyspeck)
    • Model performance metrics (R², MSE, RMSE, MAE, MAPE)

API Endpoints for Integration

The system exposes the following REST API endpoints for programmatic access:

1. Image Upload Prediction

POST /predict
Content-Type: multipart/form-data
Body: image file

Response: JSON with predictions and metrics
    

2. Camera Capture Prediction

POST /predict/camera
Content-Type: application/json
Body: {"image": "base64_encoded_image_data"}

Response: JSON with predictions and metrics
    

3. Health Check

GET /health

Response: {"status": "healthy", "uptime": "..."}
    

4. Model Information

GET /model/info

Response: Model version, metrics, and configuration
    

Troubleshooting Common Issues

Issue: pip install fails

Solution: Upgrade pip to the latest version

python -m pip install --upgrade pip
    

Issue: OpenCV installation error on Windows

Solution: Install the headless version of OpenCV

pip install opencv-python-headless
    

Issue: Port 5000 already in use

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)
    

Issue: Dataset download problems

Solution: Ensure stable internet connection and sufficient disk space. Try using a download manager for large files.

Issue: Web interface not loading

Solution: Clear browser cache, try a different browser, or restart the Flask server.

Issue: Memory error during training

Solution: Close unnecessary applications to free up RAM, or reduce the dataset size for testing purposes.

Issue: Feature extraction taking too long

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.

Issue: Models not loading in Flask app

Solution: Ensure Step 9 (train_final_models.py) completed successfully and models/ directory exists with all required files.

Project Customization Options

Modify Train-Test Split Ratios

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
    

Adjust Model Hyperparameters

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
)
    

Customize Frontend Design

Edit the following files to change appearance:

  • templates/index.html - HTML structure
  • static/css/style.css - Styling and colors
  • static/js/main.js - Client-side functionality

Add New Features

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
    

Implement Additional ML Algorithms

Follow the existing model structure to add new algorithms like SVM, Neural Networks, or Gradient Boosting variants.

Performance Optimization Tips

  • Use SSD storage for faster data loading
  • Increase RAM allocation for virtual environment
  • Enable GPU acceleration for compatible operations
  • Implement batch processing for multiple images
  • Cache model predictions to reduce computation
  • Use compressed image formats to save storage

Next Steps After Installation

  1. Review the generated visualizations in the results/ directory
  2. Analyze model performance metrics to understand accuracy
  3. Test with different apple images to validate predictions
  4. Explore the source code to understand implementation details
  5. Experiment with different feature selection methods
  6. Consider extending the project with additional features
  7. Prepare project documentation and presentation materials

Support and Assistance

If you encounter any issues during installation or have questions about the project:

  • Check the troubleshooting section above
  • Review the source code comments for implementation details
  • Contact CodeAj support for personalized assistance
  • Request project setup service for guided installation
  • Ask for source code explanation service for detailed walkthrough

Additional Resources

Verification Checklist

Before proceeding, ensure the following:

  • Python version is 3.8 or higher (check with: python --version)
  • All dependencies installed without errors
  • Dataset folder structure is correct
  • features.csv file generated successfully
  • Results directories created with visualizations
  • Models directory contains all 6 required files
  • Flask application starts without errors
  • Web interface loads in browser
  • Sample predictions work correctly

Congratulations! Your AI-Powered Apple Weight Estimation and Quality Grading System is now ready to use.

Need Help?

Our team is here to assist you with installation and setup.

Chat with Us
Chat with us