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

fixes for depth_multiplier in SeparableConv2d and DepthwiseConv2d #1008

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

dgburnette
Copy link
Contributor

@dgburnette dgburnette commented Apr 30, 2024

A# Description

The model python attached (model_asic.py) demonstrated that the shape printed by hls4ml (e.g. [None,32,32,8]) did not agree with the python model.summary() (e.g. [None,32,32,40)).
It turns out to be an incomplete handling of depth_multiplier in the SeparableConv2d and DepthwiseConv2d implementations.

Type of change

For a new feature or function, please create an issue first to discuss it
with us before submitting a pull request.

Note: Please delete options that are not relevant.

  • Bug fix (non-breaking change that fixes an issue)
  • Documentation update
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • A new research paper code implementation
  • Other (Specify)

Tests

import os
import shutil
import sys
import hls4ml
import yaml
import pickle
import argparse
import numpy as np
import tensorflow as tf
import json
from tensorflow import keras
from tensorflow.keras.models import model_from_json
from tensorflow.keras import regularizers
from tensorflow.keras.constraints import max_norm
from qkeras import *
from sklearn.metrics import accuracy_score
model = tf.keras.Sequential(name='depthwiseconv2d')
model.add(DepthwiseConv2D(kernel_size=(1,1), padding='valid', depth_multiplier=5, strides=1, dilation_rate=1, use_bias=True, input_shape=(32,32,8)))
model.compile(loss='sparse_categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
model.save(model.name + '.h5')
model.save_weights(model.name + '_weights.h5')
with open(model.name + '.json', 'w') as outfile:
outfile.write(model.to_json())
proj_name = 'myproject'
out_dir = 'my-Catapult-test_asic'
model.summary()
config_ccs = {}
config_ccs['Backend'] = 'Catapult'
config_ccs['ClockPeriod'] = 10
config_ccs['HLSConfig'] = {'Model': {'Precision': 'ac_fixed<16,8>', 'ReuseFactor': 1, 'Strategy': 'Latency'}}
config_ccs['IOType'] = 'io_stream'
config_ccs['KerasH5'] = model.name+'_weights.h5'
config_ccs['KerasJson'] = model.name+'.json'
config_ccs['ProjectName'] = proj_name
config_ccs['ASICLibs'] = 'saed32rvt_tt0p78v125c_beh'
config_ccs['FIFO'] = 'hls4ml_lib.mgc_pipe_mem'
config_ccs['OutputDir'] = out_dir
hls_model_ccs = hls4ml.converters.keras_to_hls(config_ccs)

Test Configuration:

Checklist

  • I have read the guidelines for contributing.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have made corresponding changes to the documentation.
  • My changes generate no new warnings.
  • I have installed and run pre-commit on the files I edited or added.
  • I have added tests that prove my fix is effective or that my feature works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants