Attribute Recognition


REVISION HISTORY

Revision No.
Description
Date
1.0
  • First version
  • 09/19/2023
    1.1
  • Second version
  • 10/17/2023

    1. Overview

    1.1. Overview

    Attribute recognition algorithms include: face attribute recognition, facial expression recognition, and vehicle attribute recognition.

    Model Function Version Attribute Category Output Index Information
    far103_224y.img face attributes recognition FAR101 eye_glasses, gender, mask, mustache, age face attribute index
    far101_224y_emo.img face emotion recognition FAR101 normal, happy, sad, surprise, fear, digust, anger face emotion index, when the output value is -1, it means that it cannot be recognized
    var100_224y.img vehicle attributes recognition VAR100 vehicle color, vehicle type, vehicle logo vehicle color index, vehicle type index, vehicle logo index, when the output value is -1, it means that it cannot be recognized

    2. API Reference

    This function module provides the following APIs:

    API Name Function
    ALGO_ATTR_CreateHandle Create handle
    ALGO_ATTR_InitHandle Initialize handle
    ALGO_ATTR_GetInputAttr Get the attribute information of the model
    ALGO_ATTR_SetParams Set model parameters
    ALGO_ATTR_Run Enter the attribute recognition algorithm
    ALGO_ATTR_DeInitHandle Deinitialization handle
    ALGO_ATTR_ReleaseHandle Release handle

    2.1. ALGO_ATTR_CreateHandle

    • Function

      Create handle

    • Syntax

      MI_S32 ALGO_ATTR_CreateHandle (void **handle);
      
    • Parameter

      Parameter Name Description Input/Output
      handle handle input
    • Return Value

      Return Value Description
      0 success
      other Error Code
    • Dependency

      • Header file:sgs_attr_api.h

      • Library file:libsgsalgo_attr.a/libsgsalgo_attr.so

    2.2. ALGO_ATTR_InitHandle

    • Function

      Initialize handle

    • Syntax

      MI_S32 ALGO_ATTR_InitHandle (void *handle, AttrInitInfo_t *init_info);
      
    • Parameter

      Parameter Name Description Input/Output
      handle handle Input
      init_info configure ipu_firmware_path and model folder path Input
    • Return Value

      Return Value Description
      0 success
      other Error Code
    • Dependency

      • Header file:sgs_attr_api.h

      • Library file:libsgsalgo_attr.a/libsgsalgo_attr.so

    2.3. ALGO_ATTR_GetInputAttr

    • Function

      Get the model's attribute information, including the model input resolution and the type of input data

    • Syntax

      MI_S32 ALGO_ATTR_GetInputAttr (void *handle, AttrInputAttr_t *attr_input);
      
    • Parameter

      Parameter Name Description Input/Output
      handle handle input
      attr_input output structure output
    • Return Value

      Return Value Description
      0 success
      other Error Code
    • Dependency

      • Header file:sgs_attr_api.h

      • Library file:libsgsalgo_attr.a/libsgsalgo_attr.so

    2.4. ALGO_ATTR_SetParams

    • Function

      Set model parameters

    • Syntax

      MI_S32 ALGO_ATTR_SetParams (void *handle, AttrParam_t *attr_params);
      
    • Parameter

      Parameter Name Description Input/Output
      handle handle input
      attr_params configurable parameters input
    • Return Value

      Return Value Description
      0 success
      other Error Code
    • Dependency

      • Header file:sgs_attr_api.h

      • Library file:libsgsalgo_attr.a/libsgsalgo_attr.so

    2.5. ALGO_ATTR_Run

    • Function

      Enter the attribute recognition algorithm

    • Syntax

      MI_S32 ALGO_ATTR_Run (void *handle, ALGO_AttrInput_t *attr_input, Attr_t *results);
      
    • Parameter

      Parameter Name Description Input/Output
      handle handle input
      attr_input Input buffer input
      results model output structure output
    • Return Value

      Return Value Description
      0 success
      other Error Code
    • Dependency

      • Header file:sgs_attr_api.h

      • Library file:libsgsalgo_attr.a/libsgsalgo_attr.so

    2.6. ALGO_ATTR_DeInitHandle

    • Function

      Deinitialization handle

    • Syntax

      MI_S32 ALGO_ATTR_DeInitHandle (void *handle);
      
    • Parameter

      Parameter Name Description Input/Output
      handle handle input
    • Return Value

      Return Value Description
      0 success
    • Dependency

      • Header file:sgs_attr_api.h

      • Library file:libsgsalgo_attr.a/libsgsalgo_attr.so

    2.7. ALGO_ATTR_ReleaseHandle

    • Function

      Deleting a handle

    • Syntax

      MI_S32 ALGO_ATTR_ReleaseHandle (void *handle);
      
    • Parameter

      Parameter Name Description Input/Output
      handle handle input
    • Return Value

      Return Value Description
      0 success
    • Dependency

      • Header file:sgs_attr_api.h

      • Library file:libsgsalgo_attr.a/libsgsalgo_attr.so

    3. Structure Type

    The attribute recognize related data types are defined as follows:

    Data Type Definition
    ALGO_MODEL_TYPE_ATTR_e Attribute type enumeration
    AttrFace_t Face attribute structure
    AttrVehicle_t Vehicle attribute structure
    AttrEmotion_t Facial expression attribute structure
    Attr_t Attribute type structure
    AttrInputAttr_t Model input structure
    AttrInitInfo_t Algorithm initialization parameter structure
    ALGO_AttrInput_t Algorithm input parameter structure
    AttrParam_t Algorithm configurable parameter related structures

    3.1 ALGO_MODEL_TYPE_ATTR_e

    • Description

      Algorithm identification type enumeration

    • Definition

      typedef enum
      {
          ATTR_TYPE_FACE,
          ATTR_TYPE_VEHICLE,
          ATTR_TYPE_EMOTION,
      }ALGO_MODEL_TYPE_ATTR_e;
      
    • Member

      Member Name Description
      ATTR_TYPE_FACE face attribute recognition
      ATTR_TYPE_VEHICLE vehicle attribute recognition
      ATTR_TYPE_EMOTION facial expression recognition
    • Related data type and interface

      ALGO_ATTR_Run

    3.2 AttrFace_t

    • Description

      Face attribute output information

    • Definition

      typedef struct AttrFace_
      {
          MI_BOOL eye_glass;
          MI_BOOL male;
          MI_BOOL mask;
          MI_S32  age;
          MI_BOOL mustache;
      }AttrFace_t;
      
    • Member

      Member Name Description
      eye_glass glasses
      male gender
      mask mask
      age age
      mustache mustache
    • Related data type and interface

      ALGO_ATTR_Run

    3.3 AttrVehicle_t

    • Description

      Vehicle attribute output information

    • Definition

      typedef struct AttrVehicle_
      {
          MI_S32 color;
          MI_S32 type;
          MI_S32 logo;
      }AttrVehicle_t;
      
    • Member

      Member Name Description
      color vehicle color
      type vehicle type
      logo vehicle logo
    • Related data type and interface

      ALGO_ATTR_Run

    3.4 AttrEmotion_t

    • Description

      Facial expression attribute output information

    • Definition

      typedef struct AttrEmotion_
      {
          MI_S32  emotion;
      }AttrEmotion_t;
      
    • Member

      Member Name Description
      emotion emotion
    • Related data type and interface

      ALGO_ATTR_Run

    3.5 Attr_t

    • Description

      Attribute output structure

    • Definition

      typedef struct Attr_
      {
          AttrFace_t    face;
          AttrVehicle_t vehicle;
          AttrEmotion_t emotion;
      }Attr_t;
      
    • Member

      Member Name Description
      face face attribute output structure
      vehicle vehicle attribute output structure
      emotion facial expression attribute output information
    • Related data type and interface

      ALGO_ATTR_Run

    3.6 AttrInputAttr_t

    • Description

      Define the resolution size and model type

    • Definition

      typedef struct AttrInputAttr_
      {
          MI_U32 width;
          MI_U32 height;
          MI_IPU_ELEMENT_FORMAT format;
      }AttrInputAttr_t;
      
    • Member

      Member Name Description
      width width of model input data
      height height of model input data
      format type of model input data
    • Related data type and interface

      ALGO_ATTR_GetInputAttr

    3.7 AttrInitInfo_t

    • Description

      Algorithm initialization parameter structure

    • Definition

      typedef struct AttrInitInfo_
      {
          MI_U8 ipu_firmware_path[IPU_MAX_LENGTH];
          MI_U8 model_path[MODEL_MAX_LENGTH];
          MI_BOOL create_device;
          MI_BOOL destroy_device;
          void *model_buffers;
          MI_U32 model_buffer_len;
      }AttrInitInfo_t;
      
    • Member

      Member Name Description
      ipu_firmware_path[IPU_MAX_LENGTH] ipu firmware path
      model_path[MODEL_MAX_LENGTH] model path
      create_device whether to create a device
      create_device whether to destroy the device
      model_buffer Set to NULL when using model_path. Setting model_path to NULL and setting model_buffer and model_buffer_len can be used to initialize the algorithm from the model memory block.
      model_buffer_len Set it to 0 when using model_path, set the model_buffer memory block length
    • Related data type and interface

      ALGO_ATTR_InitHandle

    3.8 ALGO_AttrInput_t

    • Description

      Algorithm input parameter structure

    • Definition

      typedef struct ALGO_AttrInput_
      {
          void*  p_vir_addr;
          MI_PHY phy_addr;
          MI_U32 buf_size;
          MI_S64 pts;
      }ALGO_AttrInput_t;
      
    • Member

      Member Name Description
      p_vir_addr virtual address of input buffer
      phy_addr physical address of input buffer
      buf_size length of input buffer
      pts timestamp of input buffer
    • Related data type and interface

      ALGO_ATTR_Run

    3.9 AttrParam_t

    • Description

      Algorithm configurable parameter related structures

    • Definition

      typedef struct AttrParam_
      {
          MI_FLOAT threshold;
          ALGO_MODEL_TYPE_ATTR_e model_type_attr;
      }AttrParam_t;
      
    • Member

      Member Name Description
      threshold threshold
      model_type_attr model identification type
    • Related data type and interface

      ALGO_ATTR_SetParams

    4. Error Code

    Error Code Value Description
    E_ALGO_SUCCESS 0 Operation success
    E_ALGO_HANDLE_NULL 1 Algorithm handle is null
    E_ALGO_INVALID_PARAM 2 Invalid input parameter
    E_ALGO_DEVICE_FAULT 3 Hardware error
    E_ALGO_LOADMODEL_FAIL 4 Failed to load model
    E_ALGO_INIT_FAIL 5 Algorithm initialization failed
    E_ALGO_NOT_INIT 6 Algorithm initialization failed
    E_ALGO_INPUT_DATA_NULL 7 Algorithm input data is null
    E_ALGO_INVALID_INPUT_SIZE 8 Invalid algorithm input data dimension
    E_ALGO_INVALID_LICENSE 9 Invalid license
    E_ALGO_MEMORY_OUT 10 Out of memory
    E_ALGO_FILEIO_ERROR 11 File read and write operation error
    E_ALGO_INVALID_OUTPUT_SIZE 12 Invalid algorithm output data dimension

    5. Output index description

    5.1 face attribute index

    Index EYE_GLASS GENDER MASK MUSTACHE AGE
    0 No glasses female no mask no beard 0~100 years old
    1 wearing glasses male wearing mask bearded 0~100 years old

    5.2 face emotion index

    Index Facial Expressions
    0 NORMAL
    1 HAPPY
    2 SAD
    3 SURPRISE
    4 FEAR
    5 DIGUST
    6 ANGER

    5.3 vehicle color index

    Index Vehicle Color
    0 WHITE
    1 BLACK
    2 GRAY
    3 RED
    4 BLUE
    5 GREEN
    6 BROWN
    7 YELLOW
    8 CYAN
    9 PURPLE
    10 GOLDEN

    5.4 vehicle type index

    Index Vehicle Type
    0 SEDAN
    1 SUV
    2 MINIVAN
    3 MPV
    4 BUS
    5 TRUCK
    6 PASSENGER VEHICLE
    7 PIKCUP
    8 OTHERS

    5.5

    Index Vehicle Logo
    0 Volkswagen
    1 Buick
    2 Ford
    3 Toyota
    4 NISSAN
    5 Honda
    6 Modern
    7 Wuling
    8 KIA
    9 Chevrolet
    10 Audi
    11 Mercedes-Benz
    12 Changan
    13 BMW
    14 Bao Jun
    15 Geely
    16 Harvard
    17 Citroen
    18 BYD
    19 JAC
    20 Cheryl
    21 Bestune
    22 Peugeot
    23 FAW
    24 Mazda
    25 Skoda
    26 Roewe
    27 Forland times
    28 Great Wall
    29 Land Rover
    30 Volvo
    31 Suzuki
    32 Cadillac
    33 BAIC Weiwang
    34 Southeast Motor
    35 Dongfeng Xiaokang
    36 Haima
    37 Jeep
    38 GAC Motor
    39 Zotye
    40 Lexus
    41 Yutong
    42 Foton
    43 Zhongtong
    44 Jinbei
    45 Dongfeng Fengxing
    46 Mitsubishi
    47 Subaru
    48 BAIC Senova
    49 Renualt
    50 Jing long
    51 Zhonghua
    52 Dongfeng Fengshen
    53 Dongfeng
    54 Jiangling
    55 SUNWIN
    56 Porsche
    57 MINI
    58 MG
    59 BAIC Motor
    60 HIGER
    61 Smart
    62 BAIC BJEV
    63 Lincoln
    64 Venucia
    65 Karry
    66 Dongfeng scenery
    67 DODGE
    68 Infiniti
    69 Jaguar
    70 Iveco
    71 FIAT
    72 TKNG
    73 Hafei Auto
    74 Kaima
    75 Old Scooter
    76 LUXGEN
    77 Golden Dragon
    78 Yuejin
    79 Changhe
    80 Leopaard
    81 Isuzu
    82 SAIC MAXUS
    83 Landwind
    84 BAIC Huansu
    85 Hawtai
    86 Ssangyong
    87 Zhongxing
    88 Lifan
    89 Chrysler
    90 Mustang
    91 Shaanqi Tongjia
    92 Huanghai
    93 Maserati
    94 DS
    95 Ankai
    96 Tesla
    97 Hengtong
    98 FAW General
    99 SINOTRUK
    100 ACURA
    101 Cowin
    102 Hongqi
    103 Heibao Auto
    104 Kowloon
    105 Borgward
    106 Qingdao Jiefang
    107 Wuzheng
    108 EVERUS
    109 Dongfeng Fengdu
    110 Dongfeng Shares
    111 Opel
    112 Car end
    113 SWM Motor
    114 Dongfeng Commercial
    115 QOROS
    116 Jiefang
    117 Concrete Mixer Class
    118 WAW Truck
    119 Lotus
    120 Daewoo
    121 Guangzhou Auto Geo
    122 CNJ
    123 BAIC
    124 Shenlong
    125 Bentley
    126 BAW
    127 Dangerous Goods Transport Vehicles
    128 Qingling
    129 FQT Motor
    130 Fudi
    131 Hanteng
    132 Sprinkler
    133 Shifeng
    134 Shaanxi Auto
    135 Youngman
    136 SMA Motor
    137 Yaxing
    138 Huazhong
    139 GMC
    140 Skannia
    141 North
    142 Yongyuan
    143 UFO
    144 Feichi
    145 KANDI
    146 Yingzhi
    147 Beiben
    148 Sediment truck