Skip to content

Commit bc51a44

Browse files
authored
Upsampling2D test case (#520)
* using keras upsampling2d method * Update nnet_image_stream.h * reindent and remove commends * add UpSampling2D to the supported layers * typo * testing upsampling2d iostream and io parallel * Delete test_upsampling2d.py * pytest for upsampling2d iostream and io parallel both are passed * Delete test_upsampling2d.py
1 parent 7c7b7af commit bc51a44

File tree

2 files changed

+65
-44
lines changed

2 files changed

+65
-44
lines changed
Lines changed: 64 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,64 @@
1-
#ifndef NNET_IMAGE_STREAM_H_
2-
#define NNET_IMAGE_STREAM_H_
3-
4-
#include "nnet_common.h"
5-
#include "hls_stream.h"
6-
7-
namespace nnet {
8-
9-
template<class data_T, typename CONFIG_T>
10-
void resize_nearest(
11-
hls::stream<data_T> &image,
12-
hls::stream<data_T> &resized
13-
) {
14-
assert(CONFIG_T::new_height % CONFIG_T::height == 0);
15-
assert(CONFIG_T::new_width % CONFIG_T::width == 0);
16-
constexpr unsigned ratio_height = CONFIG_T::new_height / CONFIG_T::height;
17-
constexpr unsigned ratio_width = CONFIG_T::new_width / CONFIG_T::width;
18-
constexpr unsigned ii = ratio_height * ratio_width;
19-
20-
ResizeImage: for (unsigned i = 0; i < CONFIG_T::height * CONFIG_T::width; i++) {
21-
#pragma HLS PIPELINE II=ii
22-
23-
data_T in_data = image.read();
24-
25-
ResizeNew: for (unsigned j = 0; j < ratio_height * ratio_width; j++) {
26-
#pragma HLS UNROLL
27-
28-
data_T out_data;
29-
#pragma HLS DATA_PACK variable=out_data
30-
31-
ResizeChan: for (unsigned k = 0; k < CONFIG_T::n_chan; k++) {
32-
#pragma HLS UNROLL
33-
out_data[k] = in_data[k];
34-
}
35-
36-
resized.write(out_data);
37-
}
38-
}
39-
}
40-
41-
}
42-
43-
#endif
1+
#ifndef NNET_IMAGE_STREAM_H_
2+
#define NNET_IMAGE_STREAM_H_
3+
4+
#include "nnet_common.h"
5+
#include "hls_stream.h"
6+
7+
namespace nnet {
8+
9+
template<class data_T, typename CONFIG_T>
10+
void resize_nearest(
11+
hls::stream<data_T> &image,
12+
hls::stream<data_T> &resized
13+
) {
14+
assert(CONFIG_T::new_height % CONFIG_T::height == 0);
15+
assert(CONFIG_T::new_width % CONFIG_T::width == 0);
16+
constexpr unsigned ratio_height = CONFIG_T::new_height / CONFIG_T::height;
17+
constexpr unsigned ratio_width = CONFIG_T::new_width / CONFIG_T::width;
18+
19+
20+
ImageHeight: for (unsigned h = 0; h < CONFIG_T::height; h++) {
21+
#pragma HLS PIPELINE
22+
23+
data_T data_in_row[CONFIG_T::width];
24+
25+
ImageWidth: for (unsigned i = 0; i < CONFIG_T::width; i++) {
26+
#pragma HLS UNROLL
27+
28+
data_T in_data = image.read();
29+
30+
ImageChan: for (unsigned j = 0; j < CONFIG_T::n_chan; j++) {
31+
#pragma HLS UNROLL
32+
33+
data_in_row[i][j] = in_data[j];
34+
}
35+
}
36+
37+
ResizeHeight: for (unsigned i = 0; i <ratio_height; i++) {
38+
#pragma HLS UNROLL
39+
40+
ImageWidth2: for (unsigned l = 0; l < CONFIG_T::width; l++) {
41+
#pragma HLS UNROLL
42+
43+
ResizeWidth: for (unsigned j = 0; j < ratio_width; j++) {
44+
#pragma HLS UNROLL
45+
46+
data_T out_data;
47+
#pragma HLS DATA_PACK variable=out_data
48+
49+
ResizeChan: for (unsigned k = 0; k < CONFIG_T::n_chan; k++) {
50+
#pragma HLS UNROLL
51+
52+
out_data[k] = data_in_row[l][k];
53+
}
54+
55+
resized.write(out_data);
56+
}
57+
}
58+
}
59+
}
60+
}
61+
62+
}
63+
64+
#endif

hls4ml/utils/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def config_from_keras_model(model, granularity='model', default_precision='ap_fi
100100
model_arch = json.loads(model.to_json())
101101

102102
#Define supported layers
103-
core_layers = ['InputLayer', 'Dropout', 'Flatten', 'Reshape', 'Permute']
103+
core_layers = ['InputLayer', 'Dropout', 'Flatten', 'Reshape', 'Permute', 'UpSampling2D']
104104
dense_layers = ['Dense', 'BinaryDense', 'TernaryDense']
105105
conv_layers = ['Conv1D', 'Conv2D', 'BinaryConv2D']
106106
pooling_layers = ['MaxPooling1D', 'MaxPooling2D', 'GlobalMaxPooling1D', 'GlobalMaxPooling2D', 'AveragePooling1D', 'AveragePooling2D', 'GlobalAveragePooling1D', 'GlobalAveragePooling2D']

0 commit comments

Comments
 (0)