Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creation of a qkeras zoo. #66

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

FrancescoLoro
Copy link

This folder contains a collection of networks written using two different frameworks: qkeras and larq.
Each network can be built and tested using a randomly generated dataset, the output will consist of two measurements:

  • Mean MSE, calculate the mean MSE between all the output for both networks
  • Absolute errors, calculates how many times the class predicted by one network does
    not coincide with the class predicted by the other network

The folder is divided in:

  • network_name.py is the class to build and test the networks.
  • utils.py contains share methods between all the classes.
  • results.txt are the results of the comparison between the networks.
  • ./qkeras_models contains the .json qkeras saved models.
  • ./larq_models contains the .json larq saved models.
  • ./weights please put the downloaded weights here, link to download weights is provided in the network class.

Link to the folder with all weights: https://drive.google.com/drive/folders/1pGZ6dGWvJyc9aH-TOQohm0PhORihQZ5I?usp=sharing

ALready added networks: quicknet, quicknet_small, quicknet_large, alexnet, and birealnet.

…uicknet, quicknet_small, quicknet_large, alexnet and birealnet. Each network is built in its own class and tested with the methods in utils.py file.
@googlebot googlebot added the cla: yes contribution license agreement signed label Mar 23, 2021
@FrancescoLoro FrancescoLoro changed the title First commit for the creation of a qkeras zoo. Creation of a qkeras zoo. Mar 23, 2021
zoo/alexnet.py Outdated Show resolved Hide resolved
zoo/alexnet.py Outdated
alexnet_name = "alexNet"


class alexnet():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@zhuangh zhuangh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@FrancescoLoro thank you so much for the license modification.

I added some comments to help us better understand the benchmark models.

FYI, we will discuss the larq part internally first in this week to see whether we want to include the part in this PR.

BTW, please also try to apply google python style in the code for readability. thanks!

"""
Class to create and load weights of: alexnet
Attributes:
network_name: Name of the network
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one sentence in the first line of the docstring followed by one empty line

ref: https://google.github.io/styleguide/pyguide.html#384-classes

could you use 2 or 4 spaces for the indentation? thanks

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, sure!

zoo/alexnet.py Outdated
@staticmethod
def add_qkeras_conv_block(model, filters_num, kernel_size, pool,
qnt, strides=1):
"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move one sentence in the first line followed by an empty line.

ref: https://google.github.io/styleguide/pyguide.html#383-functions-and-methods

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

zoo/birealnet.py Outdated
Add a sequence of: Activation quantization, Quantized Conv2D, reshape,
Average Pooling, Conv2D, 2x BatchNormalization
:param model: model where to add the sequence
:param filters_num: number of filters for Cov2D
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cov2D?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologize, it was a typo

zoo/birealnet.py Outdated

for _ in range(0, 3):
self.add_qkeras_residual_block(qkeras_biRealNet, 512)
qkeras_biRealNet.add(tf.keras.layers.AveragePooling2D(pool_size=(7, 7)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason of not using power of two numbers for pool_size? For example, (2,2) or (4,4)

We need to be careful here regarding the precision, if the pool_size is not power of two (49=7x7 here).

avg = sum(pool_element) / pool_size = sum(pool_element) / 49, which introduces the precision loss if we use fixed point or integer to hold avg, right.

zoo/birealnet.py Outdated
model.add(tf.keras.layers.Conv2D(filters_num, (1, 1), padding="same",
use_bias=False))
model.add(tf.keras.layers.BatchNormalization())
model.add(tf.keras.layers.BatchNormalization())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why consecutive batchnormalization layers?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In next commit I've done a complete refactor of that class, fixing also that mistake

BIREALNET_NAME = "biRealNet"


class BirealNet:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it from this paper https://arxiv.org/pdf/1808.00278.pdf

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is

…efactor of biRealNet fixing consecutive batch norm layers
Results on 100 random samples:

Alexnet:
Mean MSE for quickNet -> 0.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why it is called quickNet under AlexNet?

Absolute errors for quickNet -> 0

Binary DenseNet e28
Mean MSE for quickNet -> 0.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes contribution license agreement signed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants