forked from fastmachinelearning/hls4ml
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Upsampling2D test case (fastmachinelearning#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
- Loading branch information
1 parent
501650b
commit dde1f80
Showing
2 changed files
with
65 additions
and
44 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 |
---|---|---|
@@ -1,43 +1,64 @@ | ||
#ifndef NNET_IMAGE_STREAM_H_ | ||
#define NNET_IMAGE_STREAM_H_ | ||
|
||
#include "nnet_common.h" | ||
#include "hls_stream.h" | ||
|
||
namespace nnet { | ||
|
||
template<class data_T, typename CONFIG_T> | ||
void resize_nearest( | ||
hls::stream<data_T> &image, | ||
hls::stream<data_T> &resized | ||
) { | ||
assert(CONFIG_T::new_height % CONFIG_T::height == 0); | ||
assert(CONFIG_T::new_width % CONFIG_T::width == 0); | ||
constexpr unsigned ratio_height = CONFIG_T::new_height / CONFIG_T::height; | ||
constexpr unsigned ratio_width = CONFIG_T::new_width / CONFIG_T::width; | ||
constexpr unsigned ii = ratio_height * ratio_width; | ||
|
||
ResizeImage: for (unsigned i = 0; i < CONFIG_T::height * CONFIG_T::width; i++) { | ||
#pragma HLS PIPELINE II=ii | ||
|
||
data_T in_data = image.read(); | ||
|
||
ResizeNew: for (unsigned j = 0; j < ratio_height * ratio_width; j++) { | ||
#pragma HLS UNROLL | ||
|
||
data_T out_data; | ||
#pragma HLS DATA_PACK variable=out_data | ||
|
||
ResizeChan: for (unsigned k = 0; k < CONFIG_T::n_chan; k++) { | ||
#pragma HLS UNROLL | ||
out_data[k] = in_data[k]; | ||
} | ||
|
||
resized.write(out_data); | ||
} | ||
} | ||
} | ||
|
||
} | ||
|
||
#endif | ||
#ifndef NNET_IMAGE_STREAM_H_ | ||
#define NNET_IMAGE_STREAM_H_ | ||
|
||
#include "nnet_common.h" | ||
#include "hls_stream.h" | ||
|
||
namespace nnet { | ||
|
||
template<class data_T, typename CONFIG_T> | ||
void resize_nearest( | ||
hls::stream<data_T> &image, | ||
hls::stream<data_T> &resized | ||
) { | ||
assert(CONFIG_T::new_height % CONFIG_T::height == 0); | ||
assert(CONFIG_T::new_width % CONFIG_T::width == 0); | ||
constexpr unsigned ratio_height = CONFIG_T::new_height / CONFIG_T::height; | ||
constexpr unsigned ratio_width = CONFIG_T::new_width / CONFIG_T::width; | ||
|
||
|
||
ImageHeight: for (unsigned h = 0; h < CONFIG_T::height; h++) { | ||
#pragma HLS PIPELINE | ||
|
||
data_T data_in_row[CONFIG_T::width]; | ||
|
||
ImageWidth: for (unsigned i = 0; i < CONFIG_T::width; i++) { | ||
#pragma HLS UNROLL | ||
|
||
data_T in_data = image.read(); | ||
|
||
ImageChan: for (unsigned j = 0; j < CONFIG_T::n_chan; j++) { | ||
#pragma HLS UNROLL | ||
|
||
data_in_row[i][j] = in_data[j]; | ||
} | ||
} | ||
|
||
ResizeHeight: for (unsigned i = 0; i <ratio_height; i++) { | ||
#pragma HLS UNROLL | ||
|
||
ImageWidth2: for (unsigned l = 0; l < CONFIG_T::width; l++) { | ||
#pragma HLS UNROLL | ||
|
||
ResizeWidth: for (unsigned j = 0; j < ratio_width; j++) { | ||
#pragma HLS UNROLL | ||
|
||
data_T out_data; | ||
#pragma HLS DATA_PACK variable=out_data | ||
|
||
ResizeChan: for (unsigned k = 0; k < CONFIG_T::n_chan; k++) { | ||
#pragma HLS UNROLL | ||
|
||
out_data[k] = data_in_row[l][k]; | ||
} | ||
|
||
resized.write(out_data); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
} | ||
|
||
#endif |
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