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
Conversation
#define H_SCALE (5.0f) | ||
#define W_SCALE (5.0f) | ||
|
||
class MobilenetSSD : public BoxProperties |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 :)
27c5807
to
24845ed
Compare
For macos CI fail, rebase it to main. For static checkers fail, please take care of doxygen entries. |
3a3b714
to
1e92a36
Compare
case MP_PALM_DETECTION_BOUNDING_BOX: | ||
bdata = new MpPalmDetection (); | ||
break; | ||
default: |
There was a problem hiding this comment.
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!!)
There was a problem hiding this comment.
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 */ | ||
}; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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>
dfcdf92
to
49be3ba
Compare
There was a problem hiding this 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.
@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]). |
Let's move on and do the rest of refactoring in another PR. |
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.Self evaluation: