Example #1
0
def free():
    mem = gc.mem_free()
    b = gc.mem_free()
    gc.collect()
    a = gc.mem_free()
    print("gc %d -> %d %d" % (b, a, len(feature_list)))
    print(kpu.memtest())
Example #2
0
    def test_ai_camera():
        @ui.warp_template(ui.blank_draw)
        @ui.warp_template(ai_camera.ai_draw)
        def app_main():
            ui.display()

        import time
        last = time.ticks_ms()
        while True:
            kpu.memtest()
            try:
                print(time.ticks_ms() - last)
                last = time.ticks_ms()
                app_main()
            except Exception as e:
                # gc.collect()
                print(e)
            kpu.memtest()
Example #3
0
 def unit_test():
     gc.collect()
     kpu.memtest()
     FaceReco.load()
     kpu.memtest()
     import time
     last = time.ticks_ms()
     i = 0
     while i < 200:
         i += 1
         #print(i)
         try:
             #kpu.memtest()
             gc.collect()
             print(time.ticks_ms() - last)
             last = time.ticks_ms()
             app_main()
         except Exception as e:
             #
             print(e)
     FaceReco.free()
     gc.collect()
Example #4
0
        sensor.set_vflip(1)
        sensor.run(1)
        sensor.skip_frames()

    def get_image():
        if obj.is_init == False:
            obj.init()
            obj.is_init = True
        return sensor.snapshot()


if __name__ == "__main__":

    import KPU as kpu
    import gc

    kpu.memtest()

    lcd.init(freq=15000000)

    print('ram total : ' + str(gc.mem_free() / 1024) + ' kb')
    kpu.memtest()

    clock = time.clock()
    while (True):
        clock.tick()
        lcd.display(obj.get_image())
        print(clock.fps())
        print('ram total : ' + str(gc.mem_free() / 1024) + ' kb')
        kpu.memtest()
Example #5
0
    print(e)
    kpu.deinit(task)

'''

#path = "/flash/tack_picture.jpeg"

##img = sensor.snapshot()
##print("save image")
##img.save(path)

#print("read image")
#img = image.Image(path)
#lcd.display(img)
#print("ok")
'''
kpu.memtest()
task_fd = kpu.load(0x2C0000)
task_ld = kpu.load(0x580000)
task_fe = kpu.load(0x340000)
kpu.memtest()
clock = time.clock()

fm.register(23, fm.fpioa.GPIOHS0)
key_gpio = GPIO(GPIO.GPIOHS0, GPIO.IN)
start_processing = False


def set_key_state(*_):
    global start_processing
    start_processing = True
    def setup(self):
        print(kpu.memtest())
        self._rec = None
        self._record_count = 0
        self._loop_counter = 0
        self._last_100ms_cnt = 0
        self._next_loop_cmd_ms = 0
        self._last_active_ms = 0
        self._lcd_brightness = None
        self._charge_mode = None
        self._timestamp = None
        self._ramdisk_mount_point = "/ramdisk"
        self._task = None
        #self._mode              = "rec"
        self._mode = "auto"
        self._flag_send_img_to_C = False

        self._axp192 = pmu.axp192()
        self._axp192.enableADCs(True)
        self._axp192.enableCoulombCounter(False)
        self.set_lcd_brightness(9)

        fm.register(board_info.BUTTON_A, fm.fpioa.GPIO1)
        self.button_a = GPIO(GPIO.GPIO1, GPIO.IN, GPIO.PULL_UP)
        fm.register(board_info.BUTTON_B, fm.fpioa.GPIO2)
        self.button_b = GPIO(GPIO.GPIO2, GPIO.IN, GPIO.PULL_UP)

        fm.register(35, fm.fpioa.UART2_TX, force=True)
        fm.register(34, fm.fpioa.UART2_RX, force=True)
        baud = 115200  # 115200 1500000 3000000 4500000
        self.uart = UART(UART.UART2,
                         baud,
                         8,
                         0,
                         0,
                         timeout=1000,
                         read_buf_len=4096)

        sensor.reset()
        sensor.set_pixformat(sensor.RGB565)
        #sensor.set_pixformat(sensor.GRAYSCALE)
        #sensor.set_framesize(sensor.QVGA)
        sensor.set_framesize(sensor.QQVGA)
        #sensor.set_vflip(1)
        #sensor.set_hmirror(1) # if set 1, storange color!!!
        #sensor.set_windowing((224, 224))
        sensor.run(1)

        try:
            stat = uos.stat(self._ramdisk_mount_point)
            uos.umount(self._ramdisk_mount_point)
            # print("mount_point=", mount_point, " stat=", stat)
        except OSError as e:
            pass
        blkdev = RAMFlashDev()
        vfs = uos.VfsSpiffs(blkdev)
        vfs.mkfs(vfs)
        uos.mount(vfs, self._ramdisk_mount_point)

        lcd.init(freq=40000000)
        lcd.direction(lcd.YX_RLDU)
        lcd.clear(lcd.BLACK)
        lcd.draw_string(10, 10, "BeetleC_AutoDrive_V", lcd.CYAN, lcd.BLACK)

        if self._mode == "auto":
            #self._twoWheelSteeringThrottle = TwoWheelSteeringThrottle()
            print(kpu.memtest())
            self._task = kpu.load("/sd/model.kmodel")
            print(kpu.memtest())
Example #7
0
lcd.clear()  # Limpia la pantalla y la deja en negro

# Descripción y carga del modelo
labels = ['Acaro', 'Bueno',
          'Manchado']  # Etiquetas de la ultima capa de la red
task = kpu.load(
    '/sd/3clases.kmodel')  # Acá va al ubicación del archivo .kmodel   (CARGA)
kpu.set_outputs(task, 0, 1, 1,
                3)  # Aqúi van las dimensiones de la ultima capa de la red

while (True):

    tick1 = utime.ticks_ms()

    # Ejecucion del modelo en tiempo real
    kpu.memtest()  # Verifica la memoria disponible
    img = sensor.snapshot()  # Captura de la imagen
    fmap = kpu.forward(task,
                       img)  # Ejecuta la red neuronal con la imagen capturada
    plist = fmap[:]  # Extrae las probabilidades dentro de una lista
    pmax = max(plist)  # Escoge de las probabilidades la mayor
    max_index = plist.index(
        pmax)  # Extrae el indice de la clase con la mayor probabilidad

    tick2 = utime.ticks_ms()

    etime = utime.ticks_diff(tick2, tick1)

    # Impresion del resultado en la pantalla LCD (Etiqueta de la clase y probabilidad)
    a = img.draw_string(0,
                        0,
Example #8
0
import KPU as kpu

lcd.init()
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.set_windowing((128, 128))
sensor.set_vflip(1)
sensor.run(1)
lcd.clear()

f = open('labels.txt', 'r')
labels = f.readlines()
f.close()

print(kpu.memtest())
latency_result = None
fps_result = None


def inference(model_file):
    task = kpu.load(model_file)
    kpu.set_outputs(task, 0, 1, 1, 2)
    clock = time.clock()
    while (True):
        img = sensor.snapshot()
        clock.tick()
        fmap = kpu.forward(task, img)
        fps = clock.fps()
        plist = fmap[:]
        pmax = max(plist)