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

[Refactoring] Split bounding_box struct #4427

Merged
merged 4 commits into from May 16, 2024

Conversation

niley7464
Copy link
Contributor

@niley7464 niley7464 commented Mar 25, 2024

This patch splites properties so that bounding_box struct does not have properties for all cases.
Also some functions like bb_setOptions, bb_decode have too many if cases, so I replaced it to use pure virtual functions.

1711328080025

Self evaluation:

  1. Build test: [*]Passed [ ]Failed [ ]Skipped
  2. Run test: [*]Passed [ ]Failed [ ]Skipped

#define H_SCALE (5.0f)
#define W_SCALE (5.0f)

class MobilenetSSD : public BoxProperties
Copy link
Member

Choose a reason for hiding this comment

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

You do not need to declare subclasses in the header.
As long as we now can have separated subclasses, I recommend making separated files for subclasses and remove all info about each subclass in the header. (e.g., /ext/nnstreamer/tensor_decoder/boxproperties/mobilenetssd.cc)

Then, you can apply factory method in this base class that creates sub classes according to the property name. By properly designing this, you will not need the enums for each "subclass", too. You will need to think about how to accept "new" subclasses from the base class.

Copy link
Member

Choose a reason for hiding this comment

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

The principle is to put commonly referenced classes and definitions in header.

If a class, #define, or a function is to be referenced by a single entity (e.g., by mobile-SSD only), you don't need to put it in a header.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved subclasses to boxproperties subdir.
Thank you :)

@myungjoo
Copy link
Member

myungjoo commented May 4, 2024

For macos CI fail, rebase it to main.

For static checkers fail, please take care of doxygen entries.

@niley7464 niley7464 force-pushed the refactoring/decoder branch 5 times, most recently from 3a3b714 to 1e92a36 Compare May 13, 2024 01:53
case MP_PALM_DETECTION_BOUNDING_BOX:
bdata = new MpPalmDetection ();
break;
default:
Copy link
Member

@myungjoo myungjoo May 13, 2024

Choose a reason for hiding this comment

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

This creates dependency from the base class to its derived classes.
It should be able to add new "subclass" without changing the base class (this!).

You may let the derived classes register required data and function callbacks for this switch-case statements.

e.g.,

class derived_class : public boxproperty
{
  friend class registerer;
  class registerer {
    registerer() { /* register a function callback doing "return new derived_class();" */ }
  };

  static registerer register;
};

in the derived .cc file.

Or you may find another mechanism to let tensordec-boundingbox.cc not be modified for new box-properties. (OCP!!)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I misunderstood the previous comment because it was an unfamiliar concept.
Now base class do not need to be modifed when new derived class added or changed.

private:
gint tensor_mapping[MAX_TENSORS]; /* Output tensor index mapping */
gfloat threshold; /* Detection threshold */
};
Copy link
Member

Choose a reason for hiding this comment

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

With the previous comment satisfied (OCP), you should be able to kick all these derived classes out of this header.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved derived class to subdir!

This patch splites properties so that bounding_box struct
does not have properties for all cases.
Also some functions like bb_setOptions, bb_decode have too many if cases,
so I replaced it to use pure virtual functions.

Signed-off-by: Yelin Jeong <yelini.jeong@samsung.com>
This patch changes macro to subclass static-const variable.
Also use enum class instead of unclear integer code.

Signed-off-by: Yelin Jeong <yelini.jeong@samsung.com>
This patch removes subclasses in the tensordec-boundingbox header.
Each box properties are located inside box_properties subdir.

Signed-off-by: Yelin Jeong <yelini.jeong@samsung.com>
This patch removes dependency from Bounding box class to properties.
setBoxDecodingMode does not need to be modified even if a new box property added.

Signed-off-by: Yelin Jeong <yelini.jeong@samsung.com>
Copy link
Member

@myungjoo myungjoo left a comment

Choose a reason for hiding this comment

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

LGTM.

We still have points that break OCP, yet, but we can now proceed and fix further later.
(you can find such points by trying (mimicking) to implement another boxproperty subclass. if you need to touch tensordec-boundingbox.h/cc (you actually need at this point), it means you have more to refactor.

However, further refactoring can be in another PR later.

@jaeyun-jung
Copy link
Collaborator

jaeyun-jung commented May 16, 2024

@niley7464 Next PR, I suggest using util function gst_tensors_info_get_nth_info() to get nth tensor-info ptr when iterating struct w/num_tensors. (config->info.info[nth]).

@myungjoo
Copy link
Member

Let's move on and do the rest of refactoring in another PR.

@myungjoo myungjoo merged commit 426173a into nnstreamer:main May 16, 2024
15 checks passed
@niley7464 niley7464 deleted the refactoring/decoder branch May 17, 2024 01:10
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.

None yet

4 participants