+ if config.config['ml_quick_label_use_skip_lists']:
+ skip_list.add(image)
+ cursor += 1
+ if cursor >= len(filtered_images):
+ helper.unrender_example(image, features, filtered_lines)
+ break
+
+ # Otherwise ask about each example.
+ else:
+ labelling_keystrokes = helper.get_labelling_keystrokes()
+ valid_keystrokes = ['<', '>', 'Q', '?']
+ valid_keystrokes += labelling_keystrokes.keys()
+ prompt = ','.join(valid_keystrokes)
+ print(f'What should I do ({prompt})? ', end='')
+ sys.stdout.flush()
+ keystroke = input_utils.single_keystroke_response(valid_keystrokes)
+ print()
+ if keystroke == 'Q':
+ logger.info('Ok, stopping for now. Labeled examples are written to disk')
+ helper.unrender_example(image, features, filtered_lines)
+ break
+ elif keystroke == '?':
+ print(
+ '''
+ > = Don't label, move to the next example.
+ < = Don't label, move to the previous example.
+ Q = Quit labeling now.
+ ? = This message.
+ else = These keystrokes assign a label to the example and persist it.'''
+ )
+ time.sleep(3.0)
+
+ elif keystroke == '>':
+ cursor += 1
+ if cursor >= len(filtered_images):
+ print('Wrapping around...')
+ cursor = 0
+ elif keystroke == '<':
+ cursor -= 1
+ if cursor < 0:
+ print('Wrapping around...')
+ cursor = len(filtered_images) - 1
+ elif keystroke in labelling_keystrokes:
+ label_value = labelling_keystrokes[keystroke]
+ filtered_lines.append(f"{label_label}: {label_value}\n")
+ with open(features, 'w') as f:
+ f.writelines(line + '\n' for line in filtered_lines)
+ if config.config['ml_quick_label_use_skip_lists']:
+ skip_list.add(image)
+ cursor += 1
+ if cursor >= len(filtered_images):
+ print('Wrapping around...')
+ cursor = 0
+ else:
+ print(f'Unknown keystroke: {keystroke}')
+ helper.unrender_example(image, features, filtered_lines)
+ _maybe_write_skip_list(skip_list)