Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/add pre postprocessing example #103

Merged
merged 56 commits into from
Oct 2, 2020

Conversation

jafet-chaves
Copy link
Contributor

No description provided.

r2i::ImageFormat::Id required_format) override {
r2i::RuntimeError error;
int width;
int height;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

initialize variables

width = in_frame->GetWidth();
height = in_frame->GetHeight();

std::shared_ptr<float> processed_data = PreProcessImage((
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this indentation looks wrong

}

private:
int required_width, required_height;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one variable per line


this->required_width = required_width;
this->required_height = required_height;
this->required_format = required_format;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you create these class variables? looks like you only use them on validate and you can pass them easily as parameters of the function

required_height, 0, channels);

for (int i = 0; i < scaled_size; i += channels) {
/* RGB = (RGB - Mean)*StdDev */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RGB = (RGB - Mean) / StdDev ?


class Example: public r2i::IPreprocessing {
public:
Example () {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why example? I already now this is an example we are on the examples directory, I suggest to use meaningful name

@jafet-chaves jafet-chaves force-pushed the feature/add-pre-postprocessing-example branch from 39fcdee to 41d4568 Compare September 9, 2020 15:47
height = in_frame->GetHeight();

std::shared_ptr<float> processed_data = PreProcessImage(
reinterpret_cast<const unsigned char *>(in_frame->GetData()), width, height,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use a variable to hold the data as you did for width and height

this->scaled_ptr = std::shared_ptr<unsigned char>(new unsigned
char[scaled_size],
std::default_delete<const unsigned char[]>());
this->adjusted_ptr = std::shared_ptr<float>(new float[scaled_size],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are you storing scaled and adjusted images ptr on the class? I think you can use local variables

stbir_resize_uint8(input, width, height, 0, scaled.get(), reqwidth,
reqheight, 0, channels);
std::shared_ptr<r2i::IFrame> LoadImage(const std::string &path, int reqwidth,
int reqheight,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

variables name req_width and req_height for consistency


class TopSortPostprocessing: public r2i::IPostprocessing {
public:
std::shared_ptr<r2i::IPrediction> Apply(std::shared_ptr<r2i::IPrediction>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix indent

Copy link
Member

@rrcarlosrodriguez rrcarlosrodriguez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Pre/Post implementations should be moved to r2i, they shouldn't be in examples
  • Pre/Post implementations should have tests

@@ -32,7 +33,8 @@ class IPostprocessing {
* \param prediction returned from the model inference.
* \return Error with a description message.
*/
virtual RuntimeError Apply(IPrediction &prediction) = 0;
virtual std::shared_ptr<r2i::IPrediction> Apply(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This interface will change with my latest PR.

examples/r2i/onnxrt/inception.cc Outdated Show resolved Hide resolved
examples/r2i/onnxrt/inception.cc Outdated Show resolved Hide resolved
examples/r2i/onnxrt/inception.cc Outdated Show resolved Hide resolved
examples/r2i/onnxrt/inception.cc Outdated Show resolved Hide resolved
examples/r2i/onnxrt/inception.cc Show resolved Hide resolved
tests/unit/r2i/preprocessing/normalize.cc Show resolved Hide resolved
tests/unit/r2i/preprocessing/normalize.cc Outdated Show resolved Hide resolved
tests/unit/r2i/preprocessing/normalize.cc Outdated Show resolved Hide resolved
tests/unit/r2i/preprocessing/normalize.cc Outdated Show resolved Hide resolved

error = preprocessing->Apply(in_frame, out_frame);
LONGS_EQUAL(r2i::RuntimeError::Code::NULL_PARAMETER, error.GetCode());
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are other missing tests:

  • Invalid format?
  • Zero stddev?
  • Output height != input height
  • Output width != input width
  • Output format != output format
  • Input type not uchar
  • Output type not float

Included the following tests:
*Zero standard deviation
*Invalid input format id
@jafet-chaves jafet-chaves force-pushed the feature/add-pre-postprocessing-example branch from 7de8d7a to 0bf3c84 Compare October 2, 2020 15:08
@jafet-chaves jafet-chaves merged commit 14b3b58 into dev-0.10 Oct 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants