如何让一幅图像经历许多由概率权重决定的函数?
How to have an image go through many functions determined by probability weights?
我有一个标志。我现在正在做的是为所有这些功能设置概率权重,并且徽标一次只转到其中一个,具体取决于它的概率值。这是我的代码:
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()
。它是否会通过一个函数应该取决于它的概率权重。这是我的想法:
如何调整我的代码,使徽标根据权重经历许多转换函数?
每个操作发生的几率是否独立于其他操作?那么 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)
我有一个标志。我现在正在做的是为所有这些功能设置概率权重,并且徽标一次只转到其中一个,具体取决于它的概率值。这是我的代码:
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()
。它是否会通过一个函数应该取决于它的概率权重。这是我的想法:
如何调整我的代码,使徽标根据权重经历许多转换函数?
每个操作发生的几率是否独立于其他操作?那么 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)