示例#1
0
def load_exercice(exo_setting_path, group):
    exercice_name = choice("Choose exercice", os.listdir(exo_setting_path))
    exercice_path = os.path.join(exo_setting_path, exercice_name)

    exercice = Exercice(exercice_name, exercice_path)

    exercice.save_path = os.path.join(exercice_path, "save",
                                      group.name.split(".")[0])

    if os.path.exists(exercice.save_path):
        paths = os.listdir(exercice.save_path)
        for path in paths:
            with open(os.path.join(exercice.save_path, path), "r") as file:
                try:
                    reader = csv.reader(file, delimiter=",")
                    line = next(reader)
                    students_codes = line[:-2]
                    grade = float(line[-2])
                    comment = line[-1]
                    students = []
                    for student_code in students_codes:
                        if (student := find_student(group, student_code)):
                            students.append(student)
                        else:
                            print("ERROR cannot find code : ", student_code)
                            exit(1)

                    exercice.entries.append(
                        ExerciceEntry(students, grade, comment))
                except Exception as e:
                    print("Reading file ",
                          os.path.join(exercice.save_path, path), "got error",
                          e)
示例#2
0
文件: exercice.py 项目: lool01/Korek
def open_exercice(exercice, path):
    possible_path = os.path.join(path, exercice.name + ".py")
    if not os.path.exists(possible_path):
        possible_path = os.path.join(
            path, choice("File not found, choose plz", os.listdir(path)))

    print(possible_path)
    os.system("code \"" + possible_path + "\"")
示例#3
0
def load_students(group_path):
    group_name = choice("Choose group", os.listdir(group_path))
    group_path = os.path.join(group_path, group_name)

    group = Group(group_name, group_path)
    with open(group_path, encoding='utf-8') as file:
        reader = csv.reader(file, delimiter=",")
        # skip first column
        next(reader)
        for row in reader:
            group.students.append(Student(*(row[:5])))

    return group
示例#4
0
def augment_background(im, fgmask, rng):
    path = util.choice(get_inria_holiday_background_paths(), rng)
    background_im = improc.imread_jpeg(path)

    cam = cameralib.Camera.create2D(background_im.shape)
    cam_new = cam.copy()

    zoom_aug_factor = rng.uniform(1.2, 1.5)
    cam_new.zoom(zoom_aug_factor *
                 np.max(im.shape[:2] / np.asarray(background_im.shape[:2])))
    cam_new.center_principal_point(im.shape)
    cam_new.shift_image(util.random_uniform_disc(rng) * im.shape[0] * 0.1)
    warped_background_im = cameralib.reproject_image(background_im, cam,
                                                     cam_new, im.shape)
    return improc.blend_image(warped_background_im, im, fgmask)
示例#5
0
def object_occlude(im, rng, inplace=True):
    # Following [Sárándi et al., arxiv:1808.09316, arxiv:1809.04987]
    factor = im.shape[0] / 256
    count = rng.randint(1, 8)
    occluders = augmentation.voc_loader.load_occluders()

    for i in range(count):
        occluder, occ_mask = util.choice(occluders, rng)
        rescale_factor = rng.uniform(0.2, 1.0) * factor * FLAGS.occlude_aug_scale

        occ_mask = improc.resize_by_factor(occ_mask, rescale_factor)
        occluder = improc.resize_by_factor(occluder, rescale_factor)

        center = rng.uniform(0, im.shape[0], size=2)
        im = improc.paste_over(occluder, im, alpha=occ_mask, center=center, inplace=inplace)

    return im
示例#6
0
def augment_background(im, fgmask, rng):
    path = util.choice(get_inria_holiday_background_paths(), rng)
    background_im = improc.imread_jpeg(path)

    cam = cameralib.Camera.create2D(background_im.shape)
    cam_new = cam.copy()

    zoom_aug_factor = rng.uniform(1.2, 1.5)
    cam_new.zoom(zoom_aug_factor *
                 np.max(im.shape[:2] / np.asarray(background_im.shape[:2])))
    cam_new.center_principal_point(im.shape)
    cam_new.shift_image(util.random_uniform_disc(rng) * im.shape[0] * 0.1)

    interp_str = FLAGS.image_interpolation_train
    antialias = FLAGS.antialias_train
    interp = getattr(cv2, 'INTER_' + interp_str.upper())
    warped_background_im = cameralib.reproject_image(
        background_im,
        cam,
        cam_new,
        im.shape,
        interp=interp,
        antialias_factor=antialias)
    return improc.blend_image(warped_background_im, im, fgmask)