Skip to content

Commit 77353f1

Browse files
committed
Clean up folder structure, sensibly rename images
1 parent 4de00ac commit 77353f1

17 files changed

Lines changed: 30 additions & 166 deletions

1_getting_started/1a_train_keras.ipynb

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -115,18 +115,7 @@
115115
"id": "f3b4d39e",
116116
"metadata": {},
117117
"outputs": [],
118-
"source": [
119-
"scaler = StandardScaler()\n",
120-
"X_train_val = scaler.fit_transform(X_train_val)\n",
121-
"X_test = scaler.transform(X_test)\n",
122-
"\n",
123-
"os.makedirs('../data', exist_ok=True)\n",
124-
"np.save('../data/X_train_val.npy', X_train_val)\n",
125-
"np.save('../data/X_test.npy', X_test)\n",
126-
"np.save('../data/y_train_val.npy', y_train_val)\n",
127-
"np.save('../data/y_test.npy', y_test)\n",
128-
"np.save('../data/classes.npy', le.classes_)"
129-
]
118+
"source": "scaler = StandardScaler()\nX_train_val = scaler.fit_transform(X_train_val)\nX_test = scaler.transform(X_test)\n\nos.makedirs('../data/jet-tagging', exist_ok=True)\nnp.save('../data/jet-tagging/X_train_val.npy', X_train_val)\nnp.save('../data/jet-tagging/X_test.npy', X_test)\nnp.save('../data/jet-tagging/y_train_val.npy', y_train_val)\nnp.save('../data/jet-tagging/y_test.npy', y_test)\nnp.save('../data/jet-tagging/classes.npy', le.classes_)"
130119
},
131120
{
132121
"cell_type": "markdown",
@@ -259,4 +248,4 @@
259248
},
260249
"nbformat": 4,
261250
"nbformat_minor": 5
262-
}
251+
}

1_getting_started/1b_train_pytorch.ipynb

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -110,18 +110,7 @@
110110
"execution_count": null,
111111
"metadata": {},
112112
"outputs": [],
113-
"source": [
114-
"scaler = StandardScaler()\n",
115-
"X_train_val = scaler.fit_transform(X_train_val)\n",
116-
"X_test = scaler.transform(X_test)\n",
117-
"\n",
118-
"os.makedirs('../data', exist_ok=True)\n",
119-
"np.save('../data/X_train_val.npy', X_train_val)\n",
120-
"np.save('../data/X_test.npy', X_test)\n",
121-
"np.save('../data/y_train_val.npy', y_train_val)\n",
122-
"np.save('../data/y_test.npy', y_test)\n",
123-
"np.save('../data/classes.npy', le.classes_)"
124-
]
113+
"source": "scaler = StandardScaler()\nX_train_val = scaler.fit_transform(X_train_val)\nX_test = scaler.transform(X_test)\n\nos.makedirs('../data/jet-tagging', exist_ok=True)\nnp.save('../data/jet-tagging/X_train_val.npy', X_train_val)\nnp.save('../data/jet-tagging/X_test.npy', X_test)\nnp.save('../data/jet-tagging/y_train_val.npy', y_train_val)\nnp.save('../data/jet-tagging/y_test.npy', y_test)\nnp.save('../data/jet-tagging/classes.npy', le.classes_)"
125114
},
126115
{
127116
"cell_type": "markdown",
@@ -278,4 +267,4 @@
278267
},
279268
"nbformat": 4,
280269
"nbformat_minor": 5
281-
}
270+
}

1_getting_started/1c_hls4ml_synth.ipynb

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,7 @@
2727
"execution_count": null,
2828
"metadata": {},
2929
"outputs": [],
30-
"source": [
31-
"import os\n",
32-
"os.environ['KERAS_BACKEND'] = 'tensorflow'\n",
33-
"\n",
34-
"import numpy as np\n",
35-
"import matplotlib.pyplot as plt\n",
36-
"import sys\n",
37-
"sys.path.append('..')\n",
38-
"import plotting\n",
39-
"import hls4ml\n",
40-
"\n",
41-
"# Load the test dataset\n",
42-
"X_test = np.ascontiguousarray(np.load('../data/X_test.npy'), dtype=np.float32)\n",
43-
"y_test = np.load('../data/y_test.npy')\n",
44-
"classes = np.load('../data/classes.npy', allow_pickle=True)"
45-
]
30+
"source": "import os\nos.environ['KERAS_BACKEND'] = 'tensorflow'\n\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport sys\nsys.path.append('..')\nimport plotting\nimport hls4ml\n\n# Load the test dataset\nX_test = np.ascontiguousarray(np.load('../data/jet-tagging/X_test.npy'), dtype=np.float32)\ny_test = np.load('../data/jet-tagging/y_test.npy')\nclasses = np.load('../data/jet-tagging/classes.npy', allow_pickle=True)"
4631
},
4732
{
4833
"cell_type": "markdown",
@@ -324,4 +309,4 @@
324309
},
325310
"nbformat": 4,
326311
"nbformat_minor": 5
327-
}
312+
}

2_quantization/2a_qkeras.ipynb

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,7 @@
5151
"id": "cell-3",
5252
"metadata": {},
5353
"outputs": [],
54-
"source": [
55-
"X_train_val = np.load('../data/X_train_val.npy')\n",
56-
"X_test = np.load('../data/X_test.npy')\n",
57-
"y_train_val = np.load('../data/y_train_val.npy')\n",
58-
"y_test = np.load('../data/y_test.npy')\n",
59-
"classes = np.load('../data/classes.npy', allow_pickle=True)"
60-
]
54+
"source": "X_train_val = np.load('../data/jet-tagging/X_train_val.npy')\nX_test = np.load('../data/jet-tagging/X_test.npy')\ny_train_val = np.load('../data/jet-tagging/y_train_val.npy')\ny_test = np.load('../data/jet-tagging/y_test.npy')\nclasses = np.load('../data/jet-tagging/classes.npy', allow_pickle=True)"
6155
},
6256
{
6357
"cell_type": "markdown",
@@ -345,4 +339,4 @@
345339
},
346340
"nbformat": 4,
347341
"nbformat_minor": 5
348-
}
342+
}

2_quantization/2b_brevitas.ipynb

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,7 @@
5959
"id": "cell-3",
6060
"metadata": {},
6161
"outputs": [],
62-
"source": [
63-
"X_train_val = np.load('../data/X_train_val.npy')\n",
64-
"X_test = np.load('../data/X_test.npy')\n",
65-
"y_train_val = np.load('../data/y_train_val.npy')\n",
66-
"y_test = np.load('../data/y_test.npy')\n",
67-
"classes = np.load('../data/classes.npy', allow_pickle=True)"
68-
]
62+
"source": "X_train_val = np.load('../data/jet-tagging/X_train_val.npy')\nX_test = np.load('../data/jet-tagging/X_test.npy')\ny_train_val = np.load('../data/jet-tagging/y_train_val.npy')\ny_test = np.load('../data/jet-tagging/y_test.npy')\nclasses = np.load('../data/jet-tagging/classes.npy', allow_pickle=True)"
6963
},
7064
{
7165
"cell_type": "markdown",
@@ -419,4 +413,4 @@
419413
},
420414
"nbformat": 4,
421415
"nbformat_minor": 5
422-
}
416+
}

3_advanced_config/3a_reuse_factor.ipynb

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -30,25 +30,7 @@
3030
"id": "cell-2",
3131
"metadata": {},
3232
"outputs": [],
33-
"source": [
34-
"import os\n",
35-
"os.environ['KERAS_BACKEND'] = 'tensorflow'\n",
36-
"\n",
37-
"import numpy as np\n",
38-
"import matplotlib.pyplot as plt\n",
39-
"import sys\n",
40-
"sys.path.append('..')\n",
41-
"import plotting\n",
42-
"import hls4ml\n",
43-
"from sklearn.metrics import accuracy_score\n",
44-
"\n",
45-
"%matplotlib inline\n",
46-
"\n",
47-
"# Load the data\n",
48-
"X_test = np.ascontiguousarray(np.load('../data/X_test.npy'), dtype=np.float32)\n",
49-
"y_test = np.load('../data/y_test.npy')\n",
50-
"classes = np.load('../data/classes.npy', allow_pickle=True)"
51-
]
33+
"source": "import os\nos.environ['KERAS_BACKEND'] = 'tensorflow'\n\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport sys\nsys.path.append('..')\nimport plotting\nimport hls4ml\nfrom sklearn.metrics import accuracy_score\n\n%matplotlib inline\n\n# Load the data\nX_test = np.ascontiguousarray(np.load('../data/jet-tagging/X_test.npy'), dtype=np.float32)\ny_test = np.load('../data/jet-tagging/y_test.npy')\nclasses = np.load('../data/jet-tagging/classes.npy', allow_pickle=True)"
5234
},
5335
{
5436
"cell_type": "markdown",
@@ -103,19 +85,7 @@
10385
"cell_type": "markdown",
10486
"id": "cell-5",
10587
"metadata": {},
106-
"source": [
107-
"## What is the ReuseFactor?\n",
108-
"\n",
109-
"In the default (`ReuseFactor = 1`) configuration, hls4ml instantiates one multiplier for every weight in the network. All multiplications for a given layer happen in a single clock cycle, giving the minimum possible latency — but using the most multipliers.\n",
110-
"\n",
111-
"Setting `ReuseFactor = N` tells hls4ml to time-multiplex the same multiplier hardware across `N` weight-input pairs. This means the layer takes `N` clock cycles to compute instead of one, but uses roughly `1/N` as many multipliers.\n",
112-
"\n",
113-
"![Reuse factor diagram](../images/reuse.png)\n",
114-
"\n",
115-
"The reuse factor must evenly divide the number of weights in each layer. For example, the first layer has `16 × 64 = 1024` weights, so valid reuse factors include 1, 2, 4, 8, 16, 32, 64, etc.\n",
116-
"\n",
117-
"Changing the reuse factor does **not** change the model accuracy — the same arithmetic is performed, just spread over more clock cycles. We will verify this below."
118-
]
88+
"source": "## What is the ReuseFactor?\n\nIn the default (`ReuseFactor = 1`) configuration, hls4ml instantiates one multiplier for every weight in the network. All multiplications for a given layer happen in a single clock cycle, giving the minimum possible latency — but using the most multipliers.\n\nSetting `ReuseFactor = N` tells hls4ml to time-multiplex the same multiplier hardware across `N` weight-input pairs. This means the layer takes `N` clock cycles to compute instead of one, but uses roughly `1/N` as many multipliers.\n\n![Reuse factor diagram](../images/part3a_reuse_factor.png)\n\nThe reuse factor must evenly divide the number of weights in each layer. For example, the first layer has `16 × 64 = 1024` weights, so valid reuse factors include 1, 2, 4, 8, 16, 32, 64, etc.\n\nChanging the reuse factor does **not** change the model accuracy — the same arithmetic is performed, just spread over more clock cycles. We will verify this below."
11989
},
12090
{
12191
"cell_type": "markdown",
@@ -275,4 +245,4 @@
275245
},
276246
"nbformat": 4,
277247
"nbformat_minor": 5
278-
}
248+
}

3_advanced_config/3b_profiling.ipynb

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -34,24 +34,7 @@
3434
"id": "cell-2",
3535
"metadata": {},
3636
"outputs": [],
37-
"source": [
38-
"import os\n",
39-
"os.environ['KERAS_BACKEND'] = 'tensorflow'\n",
40-
"\n",
41-
"import numpy as np\n",
42-
"import matplotlib.pyplot as plt\n",
43-
"import sys\n",
44-
"sys.path.append('..')\n",
45-
"import plotting\n",
46-
"import hls4ml\n",
47-
"from sklearn.metrics import accuracy_score\n",
48-
"\n",
49-
"%matplotlib inline\n",
50-
"\n",
51-
"X_test = np.ascontiguousarray(np.load('../data/X_test.npy'), dtype=np.float32)\n",
52-
"y_test = np.load('../data/y_test.npy')\n",
53-
"classes = np.load('../data/classes.npy', allow_pickle=True)"
54-
]
37+
"source": "import os\nos.environ['KERAS_BACKEND'] = 'tensorflow'\n\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport sys\nsys.path.append('..')\nimport plotting\nimport hls4ml\nfrom sklearn.metrics import accuracy_score\n\n%matplotlib inline\n\nX_test = np.ascontiguousarray(np.load('../data/jet-tagging/X_test.npy'), dtype=np.float32)\ny_test = np.load('../data/jet-tagging/y_test.npy')\nclasses = np.load('../data/jet-tagging/classes.npy', allow_pickle=True)"
5538
},
5639
{
5740
"cell_type": "markdown",
@@ -385,4 +368,4 @@
385368
},
386369
"nbformat": 4,
387370
"nbformat_minor": 5
388-
}
371+
}

4_advanced_models/4a_qkeras_cnn_svhn.ipynb

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,7 @@
44
"cell_type": "markdown",
55
"id": "4a-0",
66
"metadata": {},
7-
"source": [
8-
"# Part 4a: Convolutional Neural Networks with QKeras on the SVHN dataset\n",
9-
"\n",
10-
"In this notebook we train a quantized convolutional neural network (CNN) on the [Street View House Numbers (SVHN)](http://ufldl.stanford.edu/housenumbers/) dataset and deploy it with hls4ml.\n",
11-
"\n",
12-
"The SVHN dataset consists of real-world images of house numbers extracted from Google Street View, cropped to 32×32 RGB pixels. Unlike MNIST it is a harder, more realistic problem: images can contain more than one digit, and the centre digit defines the label. Each image belongs to one of 10 classes (digits 0–9).\n",
13-
"\n",
14-
"![SVHN examples from the test set](../images/test.png)\n",
15-
"\n",
16-
"The dataset has 73,257 training images and 26,032 test images."
17-
]
7+
"source": "# Part 4a: Convolutional Neural Networks with QKeras on the SVHN dataset\n\nIn this notebook we train a quantized convolutional neural network (CNN) on the [Street View House Numbers (SVHN)](http://ufldl.stanford.edu/housenumbers/) dataset and deploy it with hls4ml.\n\nThe SVHN dataset consists of real-world images of house numbers extracted from Google Street View, cropped to 32×32 RGB pixels. Unlike MNIST it is a harder, more realistic problem: images can contain more than one digit, and the centre digit defines the label. Each image belongs to one of 10 classes (digits 0–9).\n\n![SVHN examples from the test set](../images/part4a_test_images.png)\n\nThe dataset has 73,257 training images and 26,032 test images."
188
},
199
{
2010
"cell_type": "code",
@@ -276,20 +266,7 @@
276266
"cell_type": "markdown",
277267
"id": "4a-13",
278268
"metadata": {},
279-
"source": [
280-
"## Convolutions in hls4ml\n",
281-
"\n",
282-
"hls4ml supports two I/O modes for neural networks:\n",
283-
"\n",
284-
"- **`io_parallel`**: All inputs arrive simultaneously. Suitable for small models, when all activations fit into registers.\n",
285-
"- **`io_stream`**: Data flows through the network one element at a time via FIFO buffers. Required for larger CNNs, when the full feature maps are too large to hold in registers. Shift registers maintain a sliding window of `kernel_height − 1` rows, feeding the convolution kernel one pixel at a time.\n",
286-
"\n",
287-
"See the [hls4ml documentation](https://fastmachinelearning.org/hls4ml/concepts.html) for more details.\n",
288-
"\n",
289-
"![Conv2D stream implementation](../images/conv2d_animation.gif)\n",
290-
"\n",
291-
"**Note on softmax precision:** using `auto` precision for the output of the last dense layer can produce accumulators wider than the softmax look-up tables can handle. We cap this manually with `fixed<16,6,RND,SAT>`."
292-
]
269+
"source": "## Convolutions in hls4ml\n\nhls4ml supports two I/O modes for neural networks:\n\n- **`io_parallel`**: All inputs arrive simultaneously. Suitable for small models, when all activations fit into registers.\n- **`io_stream`**: Data flows through the network one element at a time via FIFO buffers. Required for larger CNNs, when the full feature maps are too large to hold in registers. Shift registers maintain a sliding window of `kernel_height − 1` rows, feeding the convolution kernel one pixel at a time.\n\nSee the [hls4ml documentation](https://fastmachinelearning.org/hls4ml/concepts.html) for more details.\n\n![Conv2D stream implementation](../images/part4a_conv2d_animation.gif)\n\n**Note on softmax precision:** using `auto` precision for the output of the last dense layer can produce accumulators wider than the softmax look-up tables can handle. We cap this manually with `fixed<16,6,RND,SAT>`."
293270
},
294271
{
295272
"cell_type": "code",
@@ -440,4 +417,4 @@
440417
},
441418
"nbformat": 4,
442419
"nbformat_minor": 5
443-
}
420+
}

6_more_models/6a_bdt.ipynb

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,7 @@
7878
"execution_count": null,
7979
"metadata": {},
8080
"outputs": [],
81-
"source": [
82-
"X_train_val = np.load('../data/X_train_val.npy')\n",
83-
"X_test = np.load('../data/X_test.npy')\n",
84-
"y_train_val_one_hot = np.load('../data/y_train_val.npy')\n",
85-
"y_test_one_hot = np.load('../data/y_test.npy')\n",
86-
"classes = np.load('../data/classes.npy', allow_pickle=True)"
87-
]
81+
"source": "X_train_val = np.load('../data/jet-tagging/X_train_val.npy')\nX_test = np.load('../data/jet-tagging/X_test.npy')\ny_train_val_one_hot = np.load('../data/jet-tagging/y_train_val.npy')\ny_test_one_hot = np.load('../data/jet-tagging/y_test.npy')\nclasses = np.load('../data/jet-tagging/classes.npy', allow_pickle=True)"
8882
},
8983
{
9084
"cell_type": "markdown",
@@ -485,17 +479,7 @@
485479
{
486480
"cell_type": "markdown",
487481
"metadata": {},
488-
"source": [
489-
"## Build the model\n",
490-
"\n",
491-
"Now we run `build` again, running HLS Synthesis, Logic Synthesis and Place & Route, finally producing a bitfile and an archive of files that we'll need to run inference on the pynq-z2 board. \n",
492-
"\n",
493-
"**This step takes around 20 minutes.**\n",
494-
"\n",
495-
"The floorplan of the bitfile should like something like this, where the individual tree modules are highlighted in different colours:\n",
496-
"\n",
497-
"<img src=\"../images/part5_floorplan.png\" width=\"300\" />"
498-
]
482+
"source": "## Build the model\n\nNow we run `build` again, running HLS Synthesis, Logic Synthesis and Place & Route, finally producing a bitfile and an archive of files that we'll need to run inference on the pynq-z2 board. \n\n**This step takes around 20 minutes.**\n\nThe floorplan of the bitfile should like something like this, where the individual tree modules are highlighted in different colours:\n\n<img src=\"../images/part6a_bdt_floorplan.png\" width=\"300\" />"
499483
},
500484
{
501485
"cell_type": "code",
@@ -547,4 +531,4 @@
547531
},
548532
"nbformat": 4,
549533
"nbformat_minor": 4
550-
}
534+
}

_toc.yml

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
format: jb-book
22
root: README.md
33
chapters:
4-
- file: part1_getting_started.ipynb
5-
- file: part2_advanced_config.ipynb
6-
- file: part3_compression.ipynb
7-
- file: part4_quantization.ipynb
8-
- file: part5_bdt.ipynb
9-
- file: part6_cnns.ipynb
10-
- file: part7a_bitstream.ipynb
11-
- file: part7b_deployment.ipynb
12-
- file: part7c_validation.ipynb
13-
- file: part8_symbolic_regression.ipynb
4+
- file: 1_getting_started/1a_train_keras.ipynb
5+
- file: 1_getting_started/1b_train_pytorch.ipynb
6+
- file: 1_getting_started/1c_hls4ml_synth.ipynb
7+
- file: 2_quantization/2a_qkeras.ipynb
8+
- file: 2_quantization/2b_brevitas.ipynb
9+
- file: 3_advanced_config/3a_reuse_factor.ipynb
10+
- file: 3_advanced_config/3b_profiling.ipynb
11+
- file: 4_advanced_models/4a_qkeras_cnn_svhn.ipynb
12+
- file: 6_more_models/6a_bdt.ipynb

0 commit comments

Comments
 (0)