Update Samples (#52)
Αυτή η υποβολή περιλαμβάνεται σε:
υποβλήθηκε από
GitHub
γονέας
0cff7dd26f
υποβολή
c9d773d89a
@@ -50,6 +50,19 @@ int main(int argc, char **argv) {
|
||||
std::vector<RocJpegImage> output_images;
|
||||
RocJpegDecodeParams decode_params = {};
|
||||
RocJpegUtils rocjpeg_utils;
|
||||
std::vector<std::string> base_file_names;
|
||||
std::vector<int> bad_image_indices;
|
||||
std::vector<RocJpegStreamHandle> valid_rocjpeg_stream_handles;
|
||||
std::vector<RocJpegChromaSubsampling> valid_subsamplings;
|
||||
std::vector<std::vector<uint32_t>> valid_widths;
|
||||
std::vector<std::vector<uint32_t>> valid_heights;
|
||||
std::vector<std::vector<uint32_t>> valid_prior_channel_sizes;
|
||||
std::vector<RocJpegImage> valid_output_images;
|
||||
std::vector<std::string> valid_base_file_names;
|
||||
uint64_t num_bad_jpegs = 0;
|
||||
uint64_t num_jpegs_with_411_subsampling = 0;
|
||||
uint64_t num_jpegs_with_unknown_subsampling = 0;
|
||||
uint64_t num_jpegs_with_unsupported_resolution = 0;
|
||||
|
||||
RocJpegUtils::ParseCommandLine(input_path, output_file_path, save_images, device_id, rocjpeg_backend, decode_params, nullptr, &batch_size, argc, argv);
|
||||
|
||||
@@ -82,7 +95,15 @@ int main(int argc, char **argv) {
|
||||
widths.resize(batch_size, std::vector<uint32_t>(ROCJPEG_MAX_COMPONENT, 0));
|
||||
heights.resize(batch_size, std::vector<uint32_t>(ROCJPEG_MAX_COMPONENT, 0));
|
||||
subsamplings.resize(batch_size);
|
||||
std::vector<std::string> base_file_names(batch_size);
|
||||
base_file_names.resize(batch_size);
|
||||
valid_rocjpeg_stream_handles.resize(batch_size);
|
||||
valid_output_images.resize(batch_size);
|
||||
valid_prior_channel_sizes.resize(batch_size, std::vector<uint32_t>(ROCJPEG_MAX_COMPONENT, 0));
|
||||
valid_widths.resize(batch_size, std::vector<uint32_t>(ROCJPEG_MAX_COMPONENT, 0));
|
||||
valid_heights.resize(batch_size, std::vector<uint32_t>(ROCJPEG_MAX_COMPONENT, 0));
|
||||
valid_subsamplings.resize(batch_size);
|
||||
valid_base_file_names.resize(batch_size);
|
||||
|
||||
std::cout << "Decoding started, please wait! ... " << std::endl;
|
||||
for (int i = 0; i < file_paths.size(); i += batch_size) {
|
||||
int batch_end = std::min(i + batch_size, static_cast<int>(file_paths.size()));
|
||||
@@ -107,7 +128,19 @@ int main(int argc, char **argv) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
CHECK_ROCJPEG(rocJpegStreamParse(reinterpret_cast<uint8_t*>(batch_images[index].data()), file_size, rocjpeg_stream_handles[index]));
|
||||
RocJpegStatus rocjpeg_status = rocJpegStreamParse(reinterpret_cast<uint8_t*>(batch_images[index].data()), file_size, rocjpeg_stream_handles[index]);
|
||||
if (rocjpeg_status != ROCJPEG_STATUS_SUCCESS) {
|
||||
if (is_dir) {
|
||||
bad_image_indices.push_back(index);
|
||||
num_bad_jpegs++;
|
||||
std::cerr << "Skipping decoding input file: " << file_paths[j] << std::endl;
|
||||
continue;
|
||||
} else {
|
||||
std::cerr << "ERROR: Failed to parse the input jpeg stream with " << rocJpegGetErrorName(rocjpeg_status) << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
CHECK_ROCJPEG(rocJpegGetImageInfo(rocjpeg_handle, rocjpeg_stream_handles[index], &num_components, &subsamplings[index], widths[index].data(), heights[index].data()));
|
||||
|
||||
if (roi_width > 0 && roi_height > 0 && roi_width <= widths[index][0] && roi_height <= heights[index][0]) {
|
||||
@@ -116,21 +149,30 @@ int main(int argc, char **argv) {
|
||||
|
||||
rocjpeg_utils.GetChromaSubsamplingStr(subsamplings[index], chroma_sub_sampling);
|
||||
if (widths[index][0] < 64 || heights[index][0] < 64) {
|
||||
std::cerr << "The image resolution is not supported by VCN Hardware" << std::endl;
|
||||
if (is_dir) {
|
||||
std::cout << std::endl;
|
||||
bad_image_indices.push_back(index);
|
||||
num_jpegs_with_unsupported_resolution++;
|
||||
continue;
|
||||
} else
|
||||
} else {
|
||||
std::cerr << "The image resolution is not supported by VCN Hardware" << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
if (subsamplings[index] == ROCJPEG_CSS_411 || subsamplings[index] == ROCJPEG_CSS_UNKNOWN) {
|
||||
std::cerr << "The chroma sub-sampling is not supported by VCN Hardware" << std::endl;
|
||||
if (is_dir) {
|
||||
std::cout << std::endl;
|
||||
continue;
|
||||
} else
|
||||
bad_image_indices.push_back(index);
|
||||
if (subsamplings[index] == ROCJPEG_CSS_411) {
|
||||
num_jpegs_with_411_subsampling++;
|
||||
}
|
||||
if (subsamplings[index] == ROCJPEG_CSS_UNKNOWN) {
|
||||
num_jpegs_with_unknown_subsampling++;
|
||||
}
|
||||
continue;
|
||||
} else {
|
||||
std::cerr << "The chroma sub-sampling is not supported by VCN Hardware" << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
if (rocjpeg_utils.GetChannelPitchAndSizes(decode_params, subsamplings[index], widths[index].data(), heights[index].data(), num_channels, output_images[index], channel_sizes)) {
|
||||
@@ -150,16 +192,50 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
}
|
||||
}
|
||||
int current_batch_size = batch_end - i;
|
||||
int current_batch_size = batch_end - i - bad_image_indices.size();
|
||||
|
||||
auto start_time = std::chrono::high_resolution_clock::now();
|
||||
CHECK_ROCJPEG(rocJpegDecodeBatched(rocjpeg_handle, rocjpeg_stream_handles.data(), current_batch_size, &decode_params, output_images.data()));
|
||||
auto end_time = std::chrono::high_resolution_clock::now();
|
||||
double time_per_batch_in_milli_sec = std::chrono::duration<double, std::milli>(end_time - start_time).count();
|
||||
// Select valid images for decoding
|
||||
if (current_batch_size > 0) {
|
||||
if (!bad_image_indices.empty()) {
|
||||
// Iterate through the batch images and select only the valid ones
|
||||
int valid_idx = 0;
|
||||
for (int idx = 0; idx < batch_size; idx++) {
|
||||
// Check if the current image index is not in the list of bad image indices
|
||||
if (std::find(bad_image_indices.begin(), bad_image_indices.end(), idx) == bad_image_indices.end()) {
|
||||
// Add the valid image index to the corresponding vectors
|
||||
valid_rocjpeg_stream_handles[valid_idx] = rocjpeg_stream_handles[idx];
|
||||
valid_subsamplings[valid_idx] = subsamplings[idx];
|
||||
valid_widths[valid_idx] = widths[idx];
|
||||
valid_heights[valid_idx] = heights[idx];
|
||||
valid_prior_channel_sizes[valid_idx] = prior_channel_sizes[idx];
|
||||
valid_output_images[valid_idx] = output_images[idx];
|
||||
valid_base_file_names[valid_idx] = base_file_names[idx];
|
||||
valid_idx++;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// If there are no bad images, select all the batch images
|
||||
valid_rocjpeg_stream_handles = rocjpeg_stream_handles;
|
||||
valid_subsamplings = subsamplings;
|
||||
valid_widths = widths;
|
||||
valid_heights = heights;
|
||||
valid_prior_channel_sizes = prior_channel_sizes;
|
||||
valid_output_images = output_images;
|
||||
valid_base_file_names = base_file_names;
|
||||
}
|
||||
}
|
||||
|
||||
double time_per_batch_in_milli_sec = 0;
|
||||
if (current_batch_size > 0) {
|
||||
auto start_time = std::chrono::high_resolution_clock::now();
|
||||
CHECK_ROCJPEG(rocJpegDecodeBatched(rocjpeg_handle, valid_rocjpeg_stream_handles.data(), current_batch_size, &decode_params, valid_output_images.data()));
|
||||
auto end_time = std::chrono::high_resolution_clock::now();
|
||||
time_per_batch_in_milli_sec = std::chrono::duration<double, std::milli>(end_time - start_time).count();
|
||||
}
|
||||
|
||||
double image_size_in_mpixels = 0;
|
||||
for (int b = 0; b < current_batch_size; b++) {
|
||||
image_size_in_mpixels += (static_cast<double>(widths[b][0]) * static_cast<double>(heights[b][0]) / 1000000);
|
||||
image_size_in_mpixels += (static_cast<double>(valid_widths[b][0]) * static_cast<double>(valid_heights[b][0]) / 1000000);
|
||||
}
|
||||
|
||||
total_images += current_batch_size;
|
||||
@@ -168,12 +244,12 @@ int main(int argc, char **argv) {
|
||||
for (int b = 0; b < current_batch_size; b++) {
|
||||
std::string image_save_path = output_file_path;
|
||||
//if ROI is present, need to pass roi_width and roi_height
|
||||
uint32_t width = is_roi_valid ? roi_width : widths[b][0];
|
||||
uint32_t height = is_roi_valid ? roi_height : heights[b][0];
|
||||
uint32_t width = is_roi_valid ? roi_width : valid_widths[b][0];
|
||||
uint32_t height = is_roi_valid ? roi_height : valid_heights[b][0];
|
||||
if (is_dir) {
|
||||
rocjpeg_utils.GetOutputFileExt(decode_params.output_format, base_file_names[b], width, height, subsamplings[b], image_save_path);
|
||||
rocjpeg_utils.GetOutputFileExt(decode_params.output_format, valid_base_file_names[b], width, height, valid_subsamplings[b], image_save_path);
|
||||
}
|
||||
rocjpeg_utils.SaveImage(image_save_path, &output_images[b], width, height, subsamplings[b], decode_params.output_format);
|
||||
rocjpeg_utils.SaveImage(image_save_path, &valid_output_images[b], width, height, valid_subsamplings[b], decode_params.output_format);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -182,10 +258,7 @@ int main(int argc, char **argv) {
|
||||
mpixels_all += image_size_in_mpixels;
|
||||
}
|
||||
|
||||
// Clear the batch_images vector after processing each batch
|
||||
for (int j = i; j < batch_end; j++) {
|
||||
batch_images[j - i].clear();
|
||||
}
|
||||
bad_image_indices.clear();
|
||||
}
|
||||
|
||||
if (is_dir) {
|
||||
@@ -193,6 +266,22 @@ int main(int argc, char **argv) {
|
||||
images_per_sec = 1000 / time_per_image_all;
|
||||
double mpixels_per_sec = mpixels_all * images_per_sec / total_images;
|
||||
std::cout << "Total decoded images: " << total_images << std::endl;
|
||||
if (num_bad_jpegs || num_jpegs_with_411_subsampling || num_jpegs_with_unknown_subsampling || num_jpegs_with_unsupported_resolution) {
|
||||
std::cout << "Total skipped images: " << num_bad_jpegs + num_jpegs_with_411_subsampling + num_jpegs_with_unknown_subsampling + num_jpegs_with_unsupported_resolution;
|
||||
if (num_bad_jpegs) {
|
||||
std::cout << " ,total images that cannot be parsed: " << num_bad_jpegs;
|
||||
}
|
||||
if (num_jpegs_with_411_subsampling) {
|
||||
std::cout << " ,total images with YUV 4:1:1 chroam subsampling: " << num_jpegs_with_411_subsampling;
|
||||
}
|
||||
if (num_jpegs_with_unknown_subsampling) {
|
||||
std::cout << " ,total images with unknwon chroam subsampling: " << num_jpegs_with_unknown_subsampling;
|
||||
}
|
||||
if (num_jpegs_with_unsupported_resolution) {
|
||||
std::cout << " ,total images with unsupported_resolution: " << num_jpegs_with_unsupported_resolution;
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
if (total_images) {
|
||||
std::cout << "Average processing time per image (ms): " << time_per_image_all << std::endl;
|
||||
std::cout << "Average decoded images per sec (Images/Sec): " << images_per_sec << std::endl;
|
||||
|
||||
Αναφορά σε νέο ζήτημα
Block a user