-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1e52a04
commit edd5a1f
Showing
6 changed files
with
203 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from tensorflow import keras\n", | ||
"model = keras.models.load_model('model_1/KERAS_check_best_model.h5')" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Make an hls4ml config & model" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Interpreting Model\n", | ||
"Topology:\n", | ||
"Layer name: encoder_input, layer type: Input\n", | ||
"Layer name: dense_32, layer type: Dense\n", | ||
" -> Activation (relu), layer name: dense_32\n", | ||
"Layer name: dense_33, layer type: Dense\n", | ||
" -> Activation (relu), layer name: dense_33\n", | ||
"Layer name: encoder_output, layer type: Dense\n", | ||
" -> Activation (relu), layer name: encoder_output\n", | ||
"Layer name: dense_34, layer type: Dense\n", | ||
" -> Activation (relu), layer name: dense_34\n", | ||
"Layer name: dense_35, layer type: Dense\n", | ||
" -> Activation (relu), layer name: dense_35\n", | ||
"Layer name: ecoder_output, layer type: Dense\n", | ||
" -> Activation (sigmoid), layer name: ecoder_output\n", | ||
"-----------------------------------\n", | ||
"Configuration\n", | ||
"{'Model': {'Precision': 'ap_fixed<16,6>', 'ReuseFactor': 1, 'Strategy': 'Latency'}}\n", | ||
"-----------------------------------\n", | ||
"Interpreting Model\n", | ||
"Topology:\n", | ||
"Layer name: encoder_input, layer type: InputLayer, input shapes: [[None, 784]], output shape: [None, 784]\n", | ||
"Layer name: dense_32, layer type: Dense, input shapes: [[None, 784]], output shape: [None, 128]\n", | ||
"Layer name: dense_33, layer type: Dense, input shapes: [[None, 128]], output shape: [None, 64]\n", | ||
"Layer name: encoder_output, layer type: Dense, input shapes: [[None, 64]], output shape: [None, 2]\n", | ||
"Layer name: dense_34, layer type: Dense, input shapes: [[None, 2]], output shape: [None, 64]\n", | ||
"Layer name: dense_35, layer type: Dense, input shapes: [[None, 64]], output shape: [None, 128]\n", | ||
"Layer name: ecoder_output, layer type: Dense, input shapes: [[None, 128]], output shape: [None, 784]\n", | ||
"Creating HLS model\n" | ||
] | ||
}, | ||
{ | ||
"name": "stderr", | ||
"output_type": "stream", | ||
"text": [ | ||
"C:\\Users\\loren\\miniconda3\\envs\\MLinPhysics\\lib\\site-packages\\hls4ml\\converters\\__init__.py:16: UserWarning: WARNING: Pytorch converter is not enabled!\n", | ||
" warnings.warn(\"WARNING: Pytorch converter is not enabled!\")\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"import plotting\n", | ||
"import hls4ml\n", | ||
"config = hls4ml.utils.config_from_keras_model(model, granularity='model')\n", | ||
"print(\"-----------------------------------\")\n", | ||
"print(\"Configuration\")\n", | ||
"print(config)\n", | ||
"print(\"-----------------------------------\")\n", | ||
"hls_model = hls4ml.converters.convert_from_keras_model(model,\n", | ||
" hls_config=config,\n", | ||
" output_dir='model_1/hls4ml_prj',\n", | ||
" part='xcu250-figd2104-2L-e')\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 10, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Project myproject_prj does not exist. Rerun \"hls4ml build -p model_1/hls4ml_prj\".\n", | ||
"Path my-hls-test does not exist. Exiting.\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"hls_model.build()\n", | ||
"hls4ml.report.read_vivado_report('my-hls-test')\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Compile, predict" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 9, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Writing HLS project\n", | ||
"Done\n" | ||
] | ||
}, | ||
{ | ||
"ename": "FileNotFoundError", | ||
"evalue": "Could not find module 'c:\\Users\\loren\\Desktop\\CODE\\Electronics Project\\DL-model-for-FPGA\\model_1\\hls4ml_prj\\firmware\\myproject-Ee3D4600.so' (or one of its dependencies). Try using the full path with constructor syntax.", | ||
"output_type": "error", | ||
"traceback": [ | ||
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", | ||
"\u001b[1;31mFileNotFoundError\u001b[0m Traceback (most recent call last)", | ||
"\u001b[1;32m<ipython-input-9-43549258be49>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mhls_model\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcompile\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 2\u001b[0m \u001b[0mdata\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mx_test\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mascontiguousarray\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mdata\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mx_test\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 3\u001b[0m \u001b[0my_hls\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mhls_model\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mpredict\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mdata\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mx_test\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", | ||
"\u001b[1;32m~\\miniconda3\\envs\\MLinPhysics\\lib\\site-packages\\hls4ml\\model\\hls_model.py\u001b[0m in \u001b[0;36mcompile\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 544\u001b[0m \u001b[0mdlclose_func\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mrestype\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mctypes\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mc_int\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 545\u001b[0m \u001b[0mdlclose_func\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_top_function_lib\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_handle\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 546\u001b[1;33m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_top_function_lib\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mctypes\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcdll\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mLoadLibrary\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mlib_name\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 547\u001b[0m \u001b[1;32mfinally\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 548\u001b[0m \u001b[0mos\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mchdir\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mcurr_dir\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", | ||
"\u001b[1;32m~\\miniconda3\\envs\\MLinPhysics\\lib\\ctypes\\__init__.py\u001b[0m in \u001b[0;36mLoadLibrary\u001b[1;34m(self, name)\u001b[0m\n\u001b[0;32m 449\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 450\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0mLoadLibrary\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mname\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 451\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_dlltype\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mname\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 452\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 453\u001b[0m \u001b[0mcdll\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mLibraryLoader\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mCDLL\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", | ||
"\u001b[1;32m~\\miniconda3\\envs\\MLinPhysics\\lib\\ctypes\\__init__.py\u001b[0m in \u001b[0;36m__init__\u001b[1;34m(self, name, mode, handle, use_errno, use_last_error, winmode)\u001b[0m\n\u001b[0;32m 371\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 372\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mhandle\u001b[0m \u001b[1;32mis\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 373\u001b[1;33m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_handle\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0m_dlopen\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_name\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mmode\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 374\u001b[0m \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 375\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_handle\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mhandle\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", | ||
"\u001b[1;31mFileNotFoundError\u001b[0m: Could not find module 'c:\\Users\\loren\\Desktop\\CODE\\Electronics Project\\DL-model-for-FPGA\\model_1\\hls4ml_prj\\firmware\\myproject-Ee3D4600.so' (or one of its dependencies). Try using the full path with constructor syntax." | ||
] | ||
} | ||
], | ||
"source": [ | ||
"hls_model.compile()\n", | ||
"data.x_test = np.ascontiguousarray(data.x_test)\n", | ||
"y_hls = hls_model.predict(data.x_test)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"interpreter": { | ||
"hash": "789093bb736187c46b4a361b2c83e244a48ff9bb7ad40e66e5ffb40455c8edff" | ||
}, | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.8.8" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 1 | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-6.64 KB
(94%)
images/AE/Latent dimension of Autoencoder without classifier.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.