Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cestmerneil/cifar_10_pytorch_coreml
Train a CIFAR-10 model in PyTorch and export to CoreML.
https://github.com/cestmerneil/cifar_10_pytorch_coreml
cifar10 coreml macos pytorch swift
Last synced: 1 day ago
JSON representation
Train a CIFAR-10 model in PyTorch and export to CoreML.
- Host: GitHub
- URL: https://github.com/cestmerneil/cifar_10_pytorch_coreml
- Owner: CestMerNeil
- License: mit
- Created: 2024-09-13T22:31:12.000Z (13 days ago)
- Default Branch: main
- Last Pushed: 2024-09-14T11:21:06.000Z (12 days ago)
- Last Synced: 2024-09-25T01:13:05.820Z (2 days ago)
- Topics: cifar10, coreml, macos, pytorch, swift
- Language: Jupyter Notebook
- Homepage:
- Size: 1.04 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# CIFAR-10 PyTorch to CoreML Conversion
This project demonstrates how to train a Convolutional Neural Network (CNN) on the CIFAR-10 dataset using PyTorch, export the trained model to CoreML format, and use the model for inference in a macOS environment via Swift.
## Features
- Train a CNN on CIFAR-10 dataset with PyTorch.
- Export the trained PyTorch model to CoreML format.
- Use CoreML model in a macOS command-line interface using Swift.## Requirements
### Python Requirements
- Python 3.x
- PyTorch
- torchvision
- CoreMLToolsInstall dependencies via pip:
```bash
pip install torch torchvision coremltools
```### macOS Requirements
- Xcode 12+
- Swift 5.0+
- macOS 11.0+## Usage
### Model Training and Conversion
1. Train the PyTorch model using the provided `TorchModelTrain.ipynb` notebook.
2. Export the trained model to CoreML using CoreMLTools:
```python
import coremltools as ct
coreml_model = ct.convert(trained_model)
coreml_model.save('CIFAR10Net.mlmodel')
```### Swift Integration
1. Integrate the `.mlmodel` into your macOS project.
2. Use the model in Swift as shown in the example Swift code:
```swift
let model = CIFAR10NetMPS_4()
// Use the model for inference
```## Project Structure
- `TorchModelTrain.ipynb`: Jupyter notebook for training and converting the model.
- `CIFAR10NetMPS_4.mlpackage`: CoreML model package for macOS.
- `main.swift`: Example Swift code for using the CoreML model.## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.