Skip to content

Commit

Permalink
add self learn classifier support
Browse files Browse the repository at this point in the history
  • Loading branch information
Neutree committed Jun 19, 2024
1 parent 69c61b0 commit 382fed4
Show file tree
Hide file tree
Showing 5 changed files with 622 additions and 2 deletions.
1 change: 1 addition & 0 deletions components/maixcam_lib/include/maix_nn_maixcam.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
namespace maix::nn
{
err::Err maixcam_load_cvimodel(const std::string &model_path, MUD *mud_obj);
int maix_nn_self_learn_classifier_learn(std::vector<float *> &features, std::vector<float *> &features_samples, int feature_num);

class NN_MaixCam : public NNBase
{
Expand Down
Binary file modified components/maixcam_lib/lib/libmaixcam_lib.so
Binary file not shown.
14 changes: 14 additions & 0 deletions components/nn/include/maix_nn.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,20 @@ namespace maix::nn
*/
std::vector<int> shape;

/**
* Shape as one int type, multiply all dims of shape
* @maixpy maix.nn.LayerInfo.shape_int
*/
int shape_int()
{
int n = shape.size() == 0 ? 0 : 1;
for(auto i : shape)
{
n *= i;
}
return n;
}

/**
* To string
* @maixpy maix.nn.LayerInfo.to_str
Expand Down
5 changes: 3 additions & 2 deletions components/nn/include/maix_nn_classifier.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,18 +215,19 @@ namespace maix::nn
* Forward image to model, get result. Only for image input, use classify_raw for tensor input.
* @param img image, format should match model input_type, or will raise err.Exception
* @param softmax if true, will do softmax to result, or will return raw value
* @param fit image resize fit mode, default Fit.FIT_COVER, see image.Fit.
* @throw If error occurred, will raise err::Exception, you can find reason in log, mostly caused by args error or hardware error.
* @return result, a list of (label, score). In C++, you need to delete it after use.
* @maixpy maix.nn.Classifier.classify
*/
std::vector<std::pair<int, float>> *classify(image::Image &img, bool softmax = true)
std::vector<std::pair<int, float>> *classify(image::Image &img, bool softmax = true, image::Fit fit = image::FIT_COVER)
{
if (img.format() != _input_img_fmt)
{
throw err::Exception("image format not match, input_type: " + image::fmt_names[_input_img_fmt] + ", image format: " + image::fmt_names[img.format()]);
}
tensor::Tensors *outputs;
outputs = _model->forward_image(img, this->mean, this->scale, maix::image::FIT_COVER, false);
outputs = _model->forward_image(img, this->mean, this->scale, fit, false);
if (!outputs)
{
throw err::Exception("forward image failed");
Expand Down
Loading

0 comments on commit 382fed4

Please sign in to comment.