예제 #1
0
def create_dataset(**kwargs):

    yolo = YOLO(**dict(kwargs))

    input_path = os.path.expanduser(kwargs.get('input_path', ''))
    output_path = os.path.expanduser(kwargs.get('output_path', ''))
    class_name = kwargs.get('class_name', '')
    class_names = yolo._get_class()

    if class_name not in class_names:
        yolo.close_session()
        return

    class_name = class_name.replace(' ', '_')
    output_path = output_path + '/' + class_name + '_dataset/'

    try:
        os.makedirs(output_path)
    except OSError:
        pass

    for root, _, files in os.walk(input_path):
        label = os.path.basename(root).lower()
        if len(files) > 0:
            try:
                os.makedirs(output_path + label)
            except:
                pass
        for file in files:
            input_file = root + '/' + file

            try:
                image = Image.open(input_file)
            except:
                continue
            else:
                _, images = yolo.detect_image(image)
                for image in images:
                    output_file = output_path + label + '/' + str(uuid4()) + \
                        '.png'
                    image.save(output_file)

    yolo.close_session()
# create instance of the flask class
app = Flask(__name__)
app.config["DEBUG"] = True

# initialize instance of class YOLO in memory
yolo_m1 = YOLO()
# yolo_m2 = YOLO()

# set model paths
yolo_m1.model_path = 'model_data/final_model.h5'
# yolo_m2.model_path ='model_data/model_2/with_6_categories.h5'

# set anchors and txt_paths
yolo_m1.anchors_path = 'model_data/new_anchors.txt'
yolo_m1.classes_path = 'model_data/new_classes.txt'
yolo_m1.class_names = yolo_m1._get_class()
# yolo_m2.anchors_path = 'model_data/model_2/txts/anchors.txt'
# yolo_m2.classes_path = 'model_data/model_2/txts/classes.txt'
yolo_m1.anchors = yolo_m1._get_anchors()
# load models in memory
yolo_m1.boxes, yolo_m1.scores, yolo_m1.classes = yolo_m1.generate()
print("model 1 loaded successfully...")

# yolo_m2.boxes, yolo_m2.scores, yolo_m2.classes = yolo_m2.generate()
# print("model 2 loaded successfully...")


def detection_function():
    om = ''
    predictions = {}
    directory = yolo_m1.test_images_directory