0

我有一个标志。我现在正在做的是为所有这些功能设置概率权重,并且徽标一次只针对其中一个,具体取决于其概率值。这是我的代码:

augmentation_func = [(random_rotation, [brand_logo]),
                             (blurring, [brand_logo]),
                             (compression, [brand_logo]),
                             (portion_covering, [brand_logo, brand_logo_width, brand_logo_height]),
                             (perspective_transform, [logo_image, brand_logo_width, brand_logo_height]),
                             (overlaying, [logo_path]),
                             (logo_background, [logo_path])]

        (augs, args), = random.choices(augmentation_func, weights=[10,5,15,20,20,15,15])

        new_logo = random_resize(augs(*args), gameplay)

然而,这还不够。标志应该能够通过多种功能。例如。一个标志可能会通过random_rotation(),perspective_transformation()overlaying(). 它是否会通过一个函数应该取决于它的概率权重。这是我的想法:

在此处输入图像描述

如何调整我的代码,以便徽标根据权重通过许多转换函数?

4

1 回答 1

1

每个操作发生的机会是否独立于其他操作?然后random.choice()不是正确的解决方案,因为它只选择一项。相反,对于每个项目,以相应的概率选择它。例如:

if random.randrange(0, 100) < 10:
    # Crop the image (in place) at a 10% chance.
    # The chance of cropping is independent
    # of the chances of any other operation.
    brand_logo = cropping(brand_logo)
    
if random.randrange(0, 100) < 15:
    # Rotate the image (in place) at a 15% chance.
    # The chance of rotating is independent
    # of the chances of any other operation.
    brand_logo = rotating(brand_logo)
于 2021-01-19T04:58:41.453 回答