Closed
Description
Quick summary
I'm currently trying to create an HLS project for the PYNQ-ZU starting from the DeepTrack package. Specifically I'm attempting to implement as a starting point the single particle tracking example within the package. After defining the configuration and the HLS model though, compile()
generates a TypeError
.
Details
- I replicate in a separate notebook the entirety of the single particle tracking example model created with DeepTrack.
- I define the configuration and the HLS model using as
part
the part name of the Zynq UltraScale+ chip on the PYNQ-ZU board.
Using hls4ml.utils.plot_model(hls_model, show_shapes=True, show_precision=True, to_file=None)
the plotted model is shown as follows:
Steps to Reproduce
pip install deeptrack
pip install hls4ml
- Create a Jupyter notebook starting from the single particle example (link in the quick summary)
- Add the following code as next steps:
import plotting
from hls4ml.converters import convert_from_keras_model
from hls4ml.utils import config_from_keras_model
from pprint import pprint
config = config_from_keras_model(model=model, granularity="model")
hls_model = convert_from_keras_model(
model=model,
output_dir="./deeptrack_model/hls4ml_prj",
project_name="deep_track_spt",
part="XCZU5EG-SFVC784"
)
hls_model.compile()
Expected behavior
The model should compile without problems.
Actual behavior
The current traceback is generated:
Writing HLS project
Output exceeds the [size limit](command:workbench.action.openSettings?[). Open the full output data [in a text editor](command:workbench.action.openLargeOutput?1688e68f-2cf1-45f7-b1b7-a2a874d20238)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
/home/jacopo/workspace/hls4ml/deeptrack_with_hls4ml.ipynb Cell 23 in <cell line: 1>()
----> [1](vscode-notebook-cell://wsl%2Bubuntu-18.04/home/jacopo/workspace/hls4ml/deeptrack_with_hls4ml.ipynb#ch0000022vscode-remote?line=0) hls_model.compile()
File ~/.local/lib/python3.8/site-packages/hls4ml/model/hls_model.py:526, in HLSModel.compile(self)
525 def compile(self):
--> 526 self.write()
528 curr_dir = os.getcwd()
529 os.chdir(self.config.get_output_dir())
File ~/.local/lib/python3.8/site-packages/hls4ml/model/hls_model.py:523, in HLSModel.write(self)
519 return ''.join(choice(hexdigits) for m in range(length))
521 self.config.config['Stamp'] = make_stamp()
--> 523 self.config.writer.write_hls(self)
File ~/.local/lib/python3.8/site-packages/hls4ml/writer/vivado_writer.py:682, in VivadoWriter.write_hls(self, model)
680 self.write_build_script(model)
681 self.write_nnet_utils(model)
--> 682 self.write_yml(model)
683 self.write_tar(model)
684 print('Done')
File ~/.local/lib/python3.8/site-packages/hls4ml/writer/vivado_writer.py:660, in VivadoWriter.write_yml(self, model)
657 pass
659 with open(model.config.get_output_dir() + '/' + config_filename, 'w') as file:
--> 660 yaml.dump(model.config.config, file)
File /usr/lib/python3/dist-packages/yaml/__init__.py:200, in dump(data, stream, Dumper, **kwds)
195 def dump(data, stream=None, Dumper=Dumper, **kwds):
196 """
197 Serialize a Python object into a YAML stream.
198 If stream is None, return the produced string instead.
199 """
--> 200 return dump_all([data], stream, Dumper=Dumper, **kwds)
File /usr/lib/python3/dist-packages/yaml/__init__.py:188, in dump_all(documents, stream, Dumper, default_style, default_flow_style, canonical, indent, width, allow_unicode, line_break, encoding, explicit_start, explicit_end, version, tags)
186 dumper.open()
187 for data in documents:
--> 188 dumper.represent(data)
189 dumper.close()
190 finally:
File /usr/lib/python3/dist-packages/yaml/representer.py:26, in BaseRepresenter.represent(self, data)
25 def represent(self, data):
---> 26 node = self.represent_data(data)
27 self.serialize(node)
28 self.represented_objects = {}
File /usr/lib/python3/dist-packages/yaml/representer.py:47, in BaseRepresenter.represent_data(self, data)
45 data_types = type(data).__mro__
46 if data_types[0] in self.yaml_representers:
---> 47 node = self.yaml_representers[data_types[0]](self, data)
48 else:
49 for data_type in data_types:
File /usr/lib/python3/dist-packages/yaml/representer.py:205, in SafeRepresenter.represent_dict(self, data)
204 def represent_dict(self, data):
--> 205 return self.represent_mapping('tag:yaml.org,2002:map', data)
File /usr/lib/python3/dist-packages/yaml/representer.py:116, in BaseRepresenter.represent_mapping(self, tag, mapping, flow_style)
114 for item_key, item_value in mapping:
115 node_key = self.represent_data(item_key)
--> 116 node_value = self.represent_data(item_value)
117 if not (isinstance(node_key, ScalarNode) and not node_key.style):
118 best_style = False
File /usr/lib/python3/dist-packages/yaml/representer.py:51, in BaseRepresenter.represent_data(self, data)
49 for data_type in data_types:
50 if data_type in self.yaml_multi_representers:
---> 51 node = self.yaml_multi_representers[data_type](self, data)
52 break
53 else:
File /usr/lib/python3/dist-packages/yaml/representer.py:340, in Representer.represent_object(self, data)
337 function_name = '%s.%s' % (function.__module__, function.__name__)
338 if not args and not listitems and not dictitems \
339 and isinstance(state, dict) and newobj:
--> 340 return self.represent_mapping(
341 'tag:yaml.org,2002:python/object:'+function_name, state)
342 if not listitems and not dictitems \
343 and isinstance(state, dict) and not state:
344 return self.represent_sequence(tag+function_name, args)
File /usr/lib/python3/dist-packages/yaml/representer.py:116, in BaseRepresenter.represent_mapping(self, tag, mapping, flow_style)
114 for item_key, item_value in mapping:
115 node_key = self.represent_data(item_key)
--> 116 node_value = self.represent_data(item_value)
117 if not (isinstance(node_key, ScalarNode) and not node_key.style):
118 best_style = False
File /usr/lib/python3/dist-packages/yaml/representer.py:51, in BaseRepresenter.represent_data(self, data)
49 for data_type in data_types:
50 if data_type in self.yaml_multi_representers:
---> 51 node = self.yaml_multi_representers[data_type](self, data)
...
--> 315 reduce = data.__reduce_ex__(2)
316 elif hasattr(data, '__reduce__'):
317 reduce = data.__reduce__()
TypeError: cannot pickle 'weakref' object
System and version information
OS: Ubuntu 18.04 (WSL2 on Windows 10)
Python: 3.8.13
hls4ml: 0.6.0