我是python编程的初学者,在学习如何从YouTube编写项目时,我被困在下面的代码中。
完整的代码在这里:https://github.com/nikhilroxtomar/Retina-Blood-Vessel-Segmentation-using-UNET-in-TensorFlow/blob/main/data.py和YouTube,出现在24:30 - https://youtu.be/tpbWZVY2dng?t=1470 )
from albumentations import HorizontalFlip
def augment_data(images, masks, save_path, augment=True):
for idx, (x, y) in tqdm(enumerate(zip(images, masks)), total=len(images)):
""" Extracting names """
name = x.split("/")[-1].split(".")[0]
""" Reading image and mask """
x = cv2.imread(x, cv2.IMREAD_COLOR)
y = imageio.mimread(y)[0]
if augment == True:
aug = HorizontalFlip(p=1.0)
augmented = aug(image=x, mask=y)
x1 = augmented["image"]
y1 = augmented["mask"]这部分是我不明白的
if augment == True:
aug = HorizontalFlip(p=1.0)
augmented = aug(image=x, mask=y)
x1 = augmented["image"]
y1 = augmented["mask"]如何使用aug获取图像的输入参数?增广被用作字典吗?你能解释一下怎么做吗?
发布于 2021-06-20 17:36:04
aug是albumentations.augmentations.transforms.HorizontalFlip类的实例
然后,如果您查看源代码,您将看到它是从albumentations.core.transforms_interface.DualTransform类继承的,而源代码则是从BasicTransform类继承的。
查看BasicTransform类,您可以看到它实现了__call__()方法。它采用可变数量的关键字参数**kwargs,并在某些处理之后返回kwargs (即调用aug()时)。kwargs是一个带有您传递的参数的白痴。在您的例子中,密钥是image和mask。
顺便提一句,不应该是if augment == True:,而是if augment:
https://stackoverflow.com/questions/68058339
复制相似问题