Git Product home page Git Product logo

automatic-structured-pruning's Introduction

Automatic-Structured-Pruning

We have implemented a framework to support developers for an automatic structured pruning of their neural networks. In previous pruning frameworks, only weight pruning is applied here. Although the unnecessary weights are set to zero, memory must still be provided for these weights, which does not result in a reduction of the weights. Thus, no reduction of the required memory space is achieved by this either. For this reason, the Automatic-Structured-Pruning tool was developed. This tool makes it possible to perform pruning for convolutional and fully cross-linked layers. Individual filters or neurons are deleted directly from the respective layers. This results in a reduction of the weights as well as the memory requirements. The tool allows two different pruning approaches:

  • Factor: For the fully connected and convolutional layers, a factor is specified in each case, which indicates the percentage of neurons or filters to be deleted from the layer.
  • Accuracy: The minimum accuracy or the maximum loss of accuracy is specified. This defines which accuracy the neural network should still reach after pruning.

The framework is still under development and will be extended from time to time.

Additionally, the Automatic-Structured-Pruning is part of the Tool AutoFlow, which is a tool that helps developers to implement machine learning (ML) faster and easier on embedded devices. The whole workflow of a data scientist should be covered. Starting from building the ML model to the selection of the target platform to the optimization and implementation of the model on the target platform.

Features:

  • Prune of filters / channels
  • Prune of neurons
  • Automatic pruning to minimum accuracy
  • Prune metric: L1/L2 Norm for neuron Pruning

Restrictions:

  • The tool is tested with Tensorflow 2.5
  • It only supports magnitude-based pruning

Upcoming functions:

  • More prune methods not only l1/l2 norm
  • not only Sequential models to prune
  • Resnet support
  • Train from scratch
  • Do you have an new idea? Please write to [email protected], [email protected] or create an issue.

How to start?

To make it easier to get started with the framework we have created a notebook which helps you to use the functions directly. You can open the notebook in Google Colab.

automatic-structured-pruning's People

Contributors

konegen avatar r1marcus avatar vse-motec avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

automatic-structured-pruning's Issues

Absturz der GUI in UIHelperWindow

Wird in die Felder von FPS bzw. Parameter fälschlicherweise ein Buchstabe, statt einer Zahl, eingeben, stürzt die GUI sofort ab.
Fehler:
GUI.py", line 1025, in Form_clicked
FPS=int(FPS)
ValueError: invalid literal for int() with base 10: 'f'

Ordnerstruktur

Ordnerstruktur:
main --> Start.py:

  • src --> mit ganzem Sourcecode
  • examples
  • doc

Updating documentation of functions

There are some functions that are missing documentation for one or two arguments.
I have added the ones that I have spotted in the associated pull request.

When I create a model like this, there is a bug at runtime

state_input = Input(shape=(84, 84, 4), name='state_input', dtype='uint8')
advantage = Input(shape=(1,), name="adv")
state_input_1 = Lambda(layer_function)(state_input)
convlayer = Conv2D(32, (8, 8), strides=(4, 4), activation='relu', padding='valid')(state_input_1)
convlayer = Conv2D(64, (4, 4), strides=(2, 2), activation='relu', padding='valid')(convlayer)
convlayer = Conv2D(64, (3, 3), strides=(1, 1), activation='relu', padding='valid')(convlayer)
flattenlayer = Flatten()(convlayer)
denselayer = Dense(256, activation='relu')(flattenlayer)

out_actions = Dense(4, activation='softmax', name='output_actions')(denselayer)
out_value = Dense(1, name='output_value')(denselayer)
model = Model(inputs=[state_input, advantage], outputs=[out_actions, out_value])

pruned_model = pruning.factor_pruning(model, dense_prune_rate, conv_prune_rate, 'L2', num_classes=10)

Traceback (most recent call last):
File "/home/xys/primary_xingtian/xingtian-pruning/xt/structured_pruning/src/test/pruning_function_test.py", line 86, in
pruned_model = pruning.factor_pruning(model, dense_prune_rate, conv_prune_rate, 'L2', num_classes=10)
File "/home/xys/primary_xingtian/xingtian-pruning/xt/structured_pruning/src/pruning.py", line 77, in factor_pruning
num_new_neurons, num_new_filters, comp)
File "/home/xys/primary_xingtian/xingtian-pruning/xt/structured_pruning/src/pruning_helper_functions.py", line 259, in build_pruned_model
pruned_model.layers[i].set_weights(new_model_param[i])
File "/home/tank/miniconda3/envs/openmmlab/lib/python3.7/site-packages/tensorflow/python/keras/engine/base_layer.py", line 1826, in set_weights
'shape %s' % (ref_shape, weight.shape))
ValueError: Layer weight shape (1911, 180) not compatible with provided weight shape (1886, 180)

Ask for help about Automatic-Structured-Pruning

I am very interested in this knowledge and would like to further study the relevant theoretical content.

I want to learn the theory of automatic structural pruning.

I would appreciate it if you could share relevant papers or materials with me. (Preferably in written form.)

I promise to use it only for my own study.

My e-mail is [email protected]

Looking forward to your early reply.

Best regards,
Jack Sun

Readme neu machen

  • Name
  • einzeiler
  • Features
  • quickstart
  • (api)
  • Installation
  • upcoming
  • Restrictions
  • lizenz

Fehler beim Wechseln zum TargetWindow

Fehler beim Übergang von "UIMarcusWindow3" zu "UITargetWindow":
GUI.py", line 194, in TargetWindow
self.project_name = self.Window1.Projekt_Name.text()
RuntimeError: wrapped C/C++ object of type QLineEdit has been deleted

Falsches Textfeld wird in der Funktion TargetWindow(self, n) ausgelesen, muss der Funktion evtl. als Parameter übergeben werden

Towards Supporting Skip Connections

I am currently working an adding support to prune networks with skip connections.
If you are interested, I can provide all steps towards this goal as individual pull requests (as soon as I have them).

The first step is checking each layers's parent during filter / node deletion in the functions "delete_filter" and "delete_dense_neuron".
So far, these functions assume that a layer at index (i+1) has its parent at index i. However, since this is not the case for skip connections, we have to add parent layer checking.

This additional check should not affect your code in a negative way. I can provide the corresponding pull request for you to run your tests.

Absturz der GUI in UIOptiWindow

Werden in die Textfelder des Prunings Buchstaben eingeben stürzt die GUI ab.
--> Es muss überprüft werden, ob eine Zahl eingegeben wurde.

ToDo

  • EmbeddedPC Pfad hinzufügen, ohne Quantisierung.
  • FPGA und EmbeddedPC model memory entfernen.
  • Dataloader Python script in README verlinken
  • Startfenster Beschriftung Buttons. (Beschriftung in den Buttons?)
  • Autokeras Constraints herausnehmen.
  • Autkeras Pfad Dateiaufrufe abändern.
  • download Funktion Name ändern
  • Helper Datei aufspalten --> Dataloader, GUI Helper
  • Dataloaderbeispiel für MNIST
  • Dataloader für Autokeras einbauen.
  • Bilder für AutoKeras Tasks
  • Fehlende Tooltips einfügen
  • Autokeras Pfad anpassen
  • Nicht benötigte Dateien/Fenster aussortieren
  • Shape of data for regression
  • Pruning funktioniert für AutoKeras Regressionsmodelle nicht
  • Compiler beim Trainieren (nach dem Pruning) von Regressionsmodellen
  • Bild für EmbeddedPC Button (Für alle Targets, freie Bilder)
  • Deactivate tasks which are not working
  • Ventilbeispiel kann nicht konvertiert werden
  • Developer documentation. --> FAQ bspw. Change GUI layout and events, add device, add optimization, add/modify dataloader
  • Test auf Ubuntu
  • Dokumentation für Autokeras Pfad, FPGA, EmbeddedPC
  • Dokumentation was mit Dateien für MCU, FPGA, EmbeddedPC gemacht werden kann.
  • Für MCU, EmbeddedPC Funktion die aufgerufen werden, um Modell auszuführen, über Codeboxen in Readme beschreiben.
  • Tensorflow pruning durchführen, wenn eigenes Pruning nicht funktioniert.
  • Datei-, Variablen-, Funktionsnamen ändern
  • AutoKeras Dataloader Probleme mit .png Bildern? "Cleanup called..." wird durchgehend ausgegeben???
  • Genauigkeit der Modelle in GUI anzeigen (AutoKeras + nach Optimierung)
  • Accuracy pruning train und test Daten? (für Dataloader und Fileloader unterschiedliche Funktionen?)
  • Accuracy pruning mit Regressionsmodell (Compiler metrik verwenden)?
  • AutoKeras Modellaufbau ist nur sehr limitiert in der Auswahl der Hyperparameter (Anaconda3\envs\AUTOflow\Lib\site-packages\autokeras\blocks\basic.py)
  • pruning_for_accuracy --> Problem bei max_loss_acc: Evaluierung auf den Trainingsdaten, später allerdings mit den Validierungsdaten verglichen --> train_test_split vornehmen --> Split erfolgt allerdings aus den Trainingsdaten?
  • Bei Accuracy Pruning das bereits geprunte Modell für den nächsten Pruningschritt verwenden?

Copy paste error: l1 vs. l2 metric

When inspecting the code, I found a copy-paste error.
The implementation for pruning dense layers has the L1 norm
avg_neuron_w.append(np.average(np.abs(new_layer_param[0][:, i])))
and the L2 norm
avg_neuron_w.append(np.linalg.norm(new_layer_param[0][:, i]))
implemented correctly.

However, when inspecting the implementation for conv layers, the code currently is the following:
L1 norm:
avg_filter_w.append(np.average(np.abs(filters[0][:, :, :, i])))
L2 norm:
avg_filter_w.append(np.average(np.abs(filters[0][:, :, :, i])))

This looks like a copy-paste error. According to the dense layer implementation, the L2 norm for conv layers should be
avg_filter_w.append(np.linalg.norm(filters[0][:, :, :, i]))

I provide a pull request with a fix.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.