Spaces:
Sleeping
Sleeping
A newer version of the Gradio SDK is available:
6.9.0
Installation Guide for FoodViT
Prerequisites
- Python 3.8 or higher
- pip package manager
- At least 4GB RAM (8GB recommended)
- GPU support optional but recommended for faster inference
Installation Steps
1. Clone or Download the Project
Make sure you have all the project files in your directory:
app.py- Main applicationpredict.py- Command line toolconfig.py- Configurationrequirements.txt- Dependenciesmodel/bestViT_PT.pth- Trained model- All utility and interface files
2. Create a Virtual Environment (Recommended)
# Create virtual environment
python -m venv foodvit_env
# Activate virtual environment
# On Windows:
foodvit_env\Scripts\activate
# On macOS/Linux:
source foodvit_env/bin/activate
3. Install Dependencies
# Install PyTorch first (choose appropriate version for your system)
# For CPU only:
pip install torch torchvision --index-url https://download.pytorch.org/whl/cpu
# For CUDA (if you have NVIDIA GPU):
# pip install torch torchvision --index-url https://download.pytorch.org/whl/cu118
# Install other dependencies
pip install -r requirements.txt
4. Troubleshooting Dependency Issues
If you encounter dependency conflicts, try this step-by-step approach:
# 1. Install core dependencies first
pip install torch torchvision
pip install transformers==4.28.0
pip install huggingface-hub==0.15.1
pip install accelerate==0.20.3
# 2. Install image processing libraries
pip install Pillow opencv-python albumentations
# 3. Install Gradio
pip install gradio==3.35.2
# 4. Install other utilities
pip install numpy scikit-learn datasets
5. Alternative: Use Conda
If you prefer conda:
# Create conda environment
conda create -n foodvit python=3.9
conda activate foodvit
# Install PyTorch
conda install pytorch torchvision -c pytorch
# Install other packages
pip install transformers==4.28.0 huggingface-hub==0.15.1
pip install gradio==3.35.2
pip install -r requirements.txt
Testing the Installation
1. Run Basic Tests
python simple_test.py
This should show all tests passing.
2. Test the Web Interface
python app.py
Then open your browser to http://localhost:7860
3. Test Command Line Tool
# Test help
python predict.py --help
# Test with a sample image (if you have one)
python predict.py path/to/your/image.jpg
Common Issues and Solutions
Issue: "cannot import name 'split_torch_state_dict_into_shards'"
Solution: This is a version compatibility issue. Try:
pip uninstall huggingface-hub transformers accelerate
pip install huggingface-hub==0.15.1 transformers==4.28.0 accelerate==0.20.3
Issue: CUDA/GPU not working
Solution:
- Check if you have NVIDIA GPU
- Install appropriate CUDA version
- Install PyTorch with CUDA support
- Or set device to 'cpu' in
config.py
Issue: Model file not found
Solution: Ensure model/bestViT_PT.pth exists in the project directory.
Issue: Memory errors
Solution:
- Close other applications
- Use CPU instead of GPU
- Reduce batch size in configuration
System Requirements
Minimum Requirements
- Python 3.8+
- 4GB RAM
- 500MB disk space
Recommended Requirements
- Python 3.9+
- 8GB RAM
- NVIDIA GPU with CUDA support
- 1GB disk space
Verification
After successful installation, you should be able to:
- ✅ Run
python simple_test.pywithout errors - ✅ Start the web interface with
python app.py - ✅ Use command line tool with
python predict.py --help - ✅ Upload images and get predictions in the web interface
Getting Help
If you encounter issues:
- Check the error messages carefully
- Ensure all dependencies are installed correctly
- Try the troubleshooting steps above
- Check if your Python version is compatible
- Verify the model file exists and is not corrupted
Next Steps
Once installation is complete:
- Web Interface: Run
python app.pyand visithttp://localhost:7860 - Command Line: Use
python predict.pyfor batch processing - Customization: Edit
config.pyto modify settings - Development: Use the modular structure for extending functionality