This project was developed as part of the Automation Engineering Project at TU Berlin, within the Department of Industrial Automation Technology. The main goal was to reduce the dimensions of AI models through model pruning, enhancing efficiency and speed while maintaining accuracy as much as possible.
The project resulted in an interface that allows testing of the Taylor pruning method. The pruning process can be applied to CNN models in .pth
format. A sample ResNet model is available in the Models
directory.
Before proceeding with the installation, clone this repository:
# Clone the repository
git clone https://github.com/rabeaifeanyi/CNN-Model-Pruning.git
# Navigate to the project directory
cd CNN-Model-Pruning
The app can be installed in three ways: using Docker, Conda, or a virtual environment.
# Build the Docker image
docker build -t cnn-model-pruning .
Refer to the Conda Cheat Sheet for additional guidance.
# Create the environment
conda env create -f environment.yml
# Activate the environment
conda activate cnn-model-pruning
Python 3.8 or later is required.
# (Optional) Create and activate a virtual environment
python -m venv venv
source venv/bin/activate # For Unix or MacOS
venv\Scripts\activate # For Windows
# Install dependencies
pip install -r requirements.txt
- Verify that the installation was successful.
- Navigate to the CNN-Model-Pruning directory.
- Start the application using one of the following methods:
# USING DOCKER
# Start the Docker container (if no custom model is available)
docker run --gpus all -p 8080:8080 cnn-model-pruning
# Start the container with a custom model
docker run --gpus all -p 8080:8080 -v <model-path>:/app/Models/<model-name>.pth -d cnn-model-pruning # Adjust path and model name accordingly
# OTHERWISE
# Start the app using Streamlit
streamlit run main.py
- Open
http://localhost:8080
in a web browser if it does not open automatically. The following interface should appear:
-
Under Select a model, choose
Upload from files
and specify the model path:- Docker
/Models/<model-name>.pth
The sample model provided is resnet_model_mnist.pth. - Otherwise Provide the local path to the model. Example:
<dir-path>/Models/resnet_model_mnist.pth
- Docker
-
Specify the dataset path. Example: Select the MNIST dataset.
- Select the pruning method. Currently, only the Taylor pruning method is implemented!
- Set the number of training epochs.
- Define the sparsity percentage.
- If necessary, specify the image size for datasets. Note: For the sample model, set image size to 224.
- Click
Run
.
- If successful, the pruning process will start. This may take from a few minutes to several hours.
- Once completed, the results will be displayed.
- Pruned models are stored in the Models_pruned directory.
- Testing the pipeline with external models
- Validating installation instructions
- Making an accessible example project available
- Automatically detecting models in the
Models
folder instead of requiring manual input - Completing the user guide
- Implementing and integrating the APoZ pruning method
- Investigating why PyTorch pruning methods are not functioning properly
- Saving intermediate states and pruned models for better comparability (integrate Streamlit session states). Currently, users need to manually input the path of a previously pruned model.
- Ensuring that computations are not repeated if the process is interrupted or the page is refreshed (use caching or integrate Streamlit session states).
Copyright (c) 2023 TU Berlin, Institute for Machine Tools and Factory Management Department of Industrial Automation Technology Authors: Leandro Carrión Benenwart, Rabea Eschenhagen, Robert Komorowski, Sedat Süzer, Tom Wolf All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice, this list of conditions, and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice, this list of conditions, and the following disclaimer in the documentation and/or other materials provided with the distribution.
- Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.