def __init__(self, categoryname=[], samplesnumber=15, bool=False): self.row = global_value.row global_value.row = global_value.row + 1 try: del self.model except Exception: pass try: del self.classifier except Exception: pass self.classnumber = len(categoryname) self.samplesnumber = samplesnumber self.categoryname = categoryname self.img_copy = None self.cap_num = 0 self.train_status = 0 self.class_list = [] self.percent = 0 self.image_class = 0 if bool: self.model = kpu.load(0x514000) self.classifier = kpu.classifier(self.model, self.classnumber, self.samplesnumber) else: pass
class_num = 3 sample_num = 15 THRESHOLD = 11 class_names = ['class1', 'class2', 'class3'] try: del model except Exception: pass try: del classifier except Exception: pass gc.collect() model = kpu.load(0x300000) classifier = kpu.classifier(model, class_num, sample_num) cap_num = 0 train_status = 0 last_cap_time = 0 last_btn_status = 1 while 1: img = sensor.snapshot() # capture img if train_status == 0: if key.value() == 0: time.sleep_ms(30) if key.value() == 0 and (last_btn_status == 1) and (time.ticks_ms() - last_cap_time > 500): last_btn_status = 0 last_cap_time = time.ticks_ms() if cap_num < class_num: