Introduction to Brocolli
Brocolli was a project designed to facilitate the conversion and quantization of PyTorch models. It primarily served as a toolset for transforming PyTorch models into other popular deep learning formats like Caffe and ONNX, as well as performing quantization processes. However, it's important to note that Brocolli is now deprecated, meaning it is no longer being actively maintained or updated.
Key Features
Brocolli provided users with several key functionalities using Torch FX, a part of PyTorch that offers tools to transform and interpret models:
-
Model Conversion: Brocolli enabled the conversion of PyTorch models to Caffe and ONNX formats. This was particularly useful for users who needed to deploy models across different platforms or use different frameworks without reimplementing the model from scratch.
-
Model Quantization: Although not detailed in the provided text, Brocolli also featured tools for model quantization, a process that reduces model size and speeds up inference by converting weights to lower-bit representations.
How to Install Brocolli
The installation process for Brocolli was straightforward. Users could install it via pip, a package manager for Python:
pip install brocolli
Using Brocolli for Model Conversion
Converting PyTorch to Caffe
To convert a model from PyTorch to Caffe, users needed to follow these steps:
-
Ensure that Caffe was installed by running:
pip install brocolli-caffe
-
Use the following Python script as an example:
import torchvision.models as models from brocolli.converter.pytorch_caffe_parser import PytorchCaffeParser net = models.alexnet(pretrained=False) x = torch.rand(1, 3, 224, 224) pytorch_parser = PytorchCaffeParser(net, x) pytorch_parser.convert() pytorch_parser.save('alexnet')
This script converts a PyTorch AlexNet model to a Caffe format, saving the output as
alexnet.caffemodel
andalexnet.prototxt
.
Converting PyTorch to ONNX
To convert a model from PyTorch to ONNX, users could use this script:
import torchvision.models as models
from brocolli.converter.pytorch_onnx_parser import PytorchOnnxParser
net = models.alexnet(pretrained=False)
x = torch.rand(1, 3, 224, 224)
pytorch_parser = PytorchOnnxParser(net, x)
pytorch_parser.convert()
pytorch_parser.save('alexnet.onnx')
Running this would generate an alexnet.onnx
file in the current folder.
Community and Support
Although Brocolli is no longer maintained, there was a community associated with it. Users could join a QQ Group (597059928) for discussion and support while the project was active.
Final Notes
If Brocolli played a helpful role in developing projects, the developers encouraged users to give the project a star on its repository as a form of support. Despite its deprecation, Brocolli served as a useful tool for model conversion and quantization during its active period.