def _static_processing(self): self.logger.info("Static processing thread starting") idx = -1 # resume processing with the last image the user looked at last_img = settings.get('processing/last_img', None) for i, image_name in enumerate(self.images): if image_name == last_img: self.idx = i break while True: with self.condition: # wait until the user hits a key while idx == self.idx and not self.do_stop and not self.do_refresh: self.condition.wait() if self.do_stop: break idx = self.idx self.do_refresh = False # if the index is valid, then process an image if idx < len(self.images) and idx >= 0: image_name = self.images[idx] self.logger.info("Opening %s" % image_name) img = cv2.imread(image_name) if img is None: self.logger.error("Error opening %s: could not read file" % (image_name)) self.camera_widget.set_error() self.idx += self.idx_increment continue try: target_data = self.detector.process_image(img) except: logutil.log_exception(self.logger, 'error processing image') self.camera_widget.set_error(img) else: settings.set('processing/last_img', image_name) settings.save() self.logger.info('Finished processing') # note that you cannot typically interact with the UI # from another thread -- but this function is special self.camera_widget.set_target_data(target_data) self.logger.info("Static processing thread exiting")
def _live_processing(self): self.logger.info("Live processing thread starting") while True: # check for exit condition with self.lock: if self.do_stop: break # open the video capture device vc = self._initialize_live() if vc is None: continue last_log = 0 exception_occurred = False # allocate a buffer for reading h = vc.get(cv2.cv.CV_CAP_PROP_FRAME_WIDTH) w = vc.get(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT) capture_buffer = np.empty(shape=(h, w, 3), dtype=np.uint8) while True: # check for exit condition with self.lock: if self.do_stop: break image_log_enabled = self.image_log_enabled # # Read the video frame # retval, img = vc.read(capture_buffer) if retval: # log images to directory if self.img_logger is not None: tm = time.time() diff = tm - last_log if diff >= 1: if image_log_enabled: self.img_logger.log_image(img) # adjust for possible drift if diff > 1.5: last_log = tm else: last_log += 1 # # Process the image # try: target_data = self.detector.process_image(img) except: # if it happened once, it'll probably happen again. Don't flood # the logfiles... if not exception_occurred: logutil.log_exception(self.logger, 'error processing image') exception_occurred = True self.camera_widget.set_error(img) else: if exception_occurred: self.logger.info("Processing resumed, no more errors.") exception_occurred = False # note that you cannot typically interact with the UI # from another thread -- but this function is special self.camera_widget.set_target_data(target_data) else: if last_log == 0: self.logger.error("Not able to connect to camera, retrying") else: self.logger.error("Camera disconnected, retrying") self.camera_widget.set_error() break self.logger.info("Static processing thread exiting")
os.rename( os.path.join(scrpath, root_dirname, root_classified_dirname), os.path.join(scrpath, root_dirname, root_classified_dirname + '_' + nowstr + '.bak')) os.mkdir(os.path.join(scrpath, root_dirname, root_classified_dirname)) if os.path.exists(os.path.join(scrpath, root_dirname, root_weight_dirname)): subdirs = glob( os.path.join(scrpath, root_dirname, root_train_dirname, '**')) classes = [] sum_traindata = 0 for subdir in subdirs: if os.path.isdir(subdir): print('sub directory: {}'.format(subdir), datetime.datetime.now().strftime('%Y/%m/%d %H:%M:%S')) num_traindata = len(glob(os.path.join(subdir, '**'))) sum_traindata += num_traindata classes.append(os.path.basename(subdir)) test_files(classes) if __name__ == '__main__': logutil.log_start(__file__) try: main() except Exception as e: logutil.log_exception(e) finally: logutil.log_end()
glob( os.path.join(scrpath, root_dirname, root_validate_dirname, os.path.basename(subdir), '**'))) sum_traindata += num_traindata sum_validate += num_validate classes.append(os.path.basename(subdir)) # # step数100 # train(classes, sum_traindata, sum_validate, 100) # step数を徐々に増加させる # max_steps = sum_traindata//batch_size # lst = [10**i for i in range(0,int(np.log10(max_steps))+1)] lst = [1, 10, 20, 50, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000] for l in lst: train(classes, sum_traindata, sum_validate, l) # # step数自動設定 # train(classes, sum_traindata, sum_validate, None) if __name__ == '__main__': logutil.log_start(__file__) try: main() except Exception as e: logutil.log_exception(__file__, e) finally: logutil.log_end()
def _live_processing(self): self.logger.info("Live processing thread starting") while True: # check for exit condition with self.lock: if self.do_stop: break # open the video capture device vc = self._initialize_live() if vc is None: continue last_log = 0 exception_occurred = False # allocate a buffer for reading h = vc.get(cv2.cv.CV_CAP_PROP_FRAME_WIDTH) w = vc.get(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT) capture_buffer = np.empty(shape=(h, w, 3), dtype=np.uint8) while True: # check for exit condition with self.lock: if self.do_stop: break image_log_enabled = self.image_log_enabled # # Read the video frame # retval, img = vc.read(capture_buffer) if retval: # log images to directory if self.img_logger is not None: tm = time.time() diff = tm - last_log if diff >= 1: if image_log_enabled: self.img_logger.log_image(img) # adjust for possible drift if diff > 1.5: last_log = tm else: last_log += 1 # # Process the image # try: target_data = self.detector.process_image(img) except: # if it happened once, it'll probably happen again. Don't flood # the logfiles... if not exception_occurred: logutil.log_exception(self.logger, 'error processing image') exception_occurred = True self.camera_widget.set_error(img) else: if exception_occurred: self.logger.info( "Processing resumed, no more errors.") exception_occurred = False # note that you cannot typically interact with the UI # from another thread -- but this function is special self.camera_widget.set_target_data(target_data) else: if last_log == 0: self.logger.error( "Not able to connect to camera, retrying") else: self.logger.error("Camera disconnected, retrying") self.camera_widget.set_error() break self.logger.info("Static processing thread exiting")