Exemplo n.º 1
0
 def get_output_fmt(self):
     output_info = ffi.new('bmnet_output_info_t *')
     lib.bmnet_get_output_info(self.net[0], output_info)
     output_fmt = []
     for i in range(output_info.output_num):
         output_fmt.append(output_info.fmt_array[i])
     return output_fmt
Exemplo n.º 2
0
 def get_output_threshold(self):
     output_info = ffi.new('bmnet_output_info_t *')
     lib.bmnet_get_output_info(self.net[0], output_info)
     output_threshold = []
     for i in range(output_info.output_num):
         output_threshold.append(output_info.threshold_array[i])
     return output_threshold
Exemplo n.º 3
0
 def set_input_shape(self, input_shape):
     shape = ffi.new('shape_t *')
     shape.dim = input_shape.shape[0]
     shape.n = input_shape[0]
     shape.c = input_shape[1]
     shape.h = input_shape[2]
     shape.w = input_shape[3]
     lib.bmnet_set_input_shape(self.net[0], shape[0])
Exemplo n.º 4
0
 def get_output_shape(self):
     output_info = ffi.new('bmnet_output_info_t *')
     lib.bmnet_get_output_info(self.net[0], output_info)
     output_shape = []
     for i in range(output_info.output_num):
         shape = output_info.shape_array[i]
         if shape.dim == 1:
             output_shape.append([shape.n])
         elif shape.dim == 2:
             output_shape.append([shape.n, shape.c])
         elif shape.dim == 3:
             output_shape.append([shape.n, shape.c, shape.h])
         elif shape.dim == 4:
             output_shape.append([shape.n, shape.c, shape.h, shape.w])
     return output_shape
Exemplo n.º 5
0
    def set_input_shapes(self, input_shapes):
        shape_arr = []
        for i in range(len(input_shapes)):
            shape = ffi.new('shape_t *')
            shape.dim = input_shapes[i].shape[0]
            if shape.dim == 1:
                shape.n = input_shapes[i][0]
            elif shape.dim == 2:
                shape.n = input_shapes[i][0]
                shape.c = input_shapes[i][1]
            elif shape.dim == 3:
                shape.n = input_shapes[i][0]
                shape.c = input_shapes[i][1]
                shape.h = input_shapes[i][2]
            elif shape.dim == 4:
                shape.n = input_shapes[i][0]
                shape.c = input_shapes[i][1]
                shape.h = input_shapes[i][2]
                shape.w = input_shapes[i][3]
            shape_arr.append(shape[0])

        lib.bmnet_set_input_shape2(self.net[0], shape_arr, len(input_shapes))
Exemplo n.º 6
0
 def __init__(self, index):
     self.ctx = ffi.new('bmctx_t *')
     lib.bm_init(index, self.ctx)
Exemplo n.º 7
0
 def get_output_size(self):
     output_info = ffi.new('bmnet_output_info_t *')
     lib.bmnet_get_output_info(self.net[0], output_info)
     return output_info.output_size
Exemplo n.º 8
0
 def inference(self, input, output):
     output_info = ffi.new('bmnet_output_info_t *')
     lib.bmnet_get_output_info(self.net[0], output_info)
     lib.bmnet_inference(self.net[0], ffi.from_buffer(input),
                         ffi.from_buffer(output))
Exemplo n.º 9
0
 def __init__(self, bmctx, bmodel_path):
     self.net = ffi.new('bmnet_t *')
     bmodel = ffi.new('char[]', bmodel_path)
     lib.bmnet_register_bmodel(bmctx.ctx[0], bmodel, self.net)