简体   繁体   English

TypeError:得到了一个意外的关键字参数“图像”

[英]TypeError: got an unexpected keyword argument 'image'

I am getting TypeError: get_train_augs() got an unexpected keyword argument 'image', I have my augmentation functions as follows我收到 TypeError: get_train_augs() got an unexpected keyword argument 'image',我的扩充功能如下

Augmentation functions增强功能

def get_train_augs():
  return A.Compose([
                    A.Resize(IMAGE_SIZE,IMAGE_SIZE),
                    A.HorizontalFlip(p = 0.5),
                    A.VerticalFlip(p = 0.5),
  ])

def get_valid_augs():
  return A.Compose([
                    A.Resize(IMAGE_SIZE,IMAGE_SIZE),
                    
  ])

Custom segmentation dataset class自定义分割数据集类

class SegmentationDataset(Dataset):
  def __init__(self, df, augmentations=None):
    self.df = df
    self.augmentations = augmentations
  
  def __len__(self):
    return len(self.df)

  def __getitem__(self,idx):
    row = self.df.iloc[idx]

    image_path = row.images
    mask_path = row.masks

    image = cv2.imread(image_path)
    image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)

    mask = cv2.imread(mask_path, cv2.IMREAD_GRAYSCALE) # (h, w, c)
    mask = np.expand_dims(mask, axis = -1)

    if self.augmentations is not None:
      data = self.augmentations(image = image, mask = mask)

      image = data['image']
      mask = data['mask']

    # (h, w, c) -> (c, h, w)
    image = np.transpose(image,(2,0,1)).astype(np.float32)
    mask = np.transpose(mask,(2,0,1)).astype(np.float32)

    image = torch.Tensor(image)/255.0
    mask = torch.round(torch.Tensor(mask)/255.0)

    return image, mask

when I call trainset like this I am getting an error:当我像这样调用 trainset 时,出现错误:

trainset = SegmentationDataset(train_df, get_train_augs)
validset = SegmentationDataset(valid_df, get_valid_augs)

calling a random index调用随机索引

idx = 3
image, mask = trainset[idx]

The error I am getting is:我得到的错误是:

TypeError                                 Traceback (most recent call last)
<ipython-input-28-9b83781b7e3d> in <module>()
      1 idx = 3
      2 
----> 3 image, mask = trainset[idx]
      4 
      5 helper.show(image, mask)

<ipython-input-25-39872478644d> in __getitem__(self, idx)
     20 
     21     if self.augmentations is not None:
---> 22       data = self.augmentations(image = image, mask = mask)
     23 
     24       image = data['image']

TypeError: get_train_augs() got an unexpected keyword argument 'image'

try尝试

trainset = SegmentationDataset(train_df, get_train_augs())
validset = SegmentationDataset(valid_df, get_valid_augs())

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 TypeError:得到一个意外的关键字参数 - TypeError: got an unexpected keyword argument TypeError:__init __()获得了意外的关键字参数&#39;image_field&#39; - TypeError: __init__() got an unexpected keyword argument 'image_field' TypeError:得到了意外的关键字参数“ name” - TypeError: got an unexpected keyword argument “name” 类型错误:binarySearch() 得到了一个意外的关键字参数“key” - TypeError: binarySearch() got an unexpected keyword argument 'key' TypeError:histogram()得到了意外的关键字参数“ new” - TypeError: histogram() got an unexpected keyword argument 'new' TypeError:urlopen()获得了意外的关键字参数&#39;headers&#39; - TypeError: urlopen() got an unexpected keyword argument 'headers' TypeError: concatenate() 得到了一个意外的关键字参数“dtype” - TypeError: concatenate() got an unexpected keyword argument 'dtype' TypeError: mannwhitneyu() 得到了一个意外的关键字参数“方法” - TypeError: mannwhitneyu() got an unexpected keyword argument 'method' TypeError: UserCreateForm() 得到了一个意外的关键字参数“初始” - TypeError: UserCreateForm() got an unexpected keyword argument 'initial' TypeError: attrib() 得到了一个意外的关键字参数 'convert' - TypeError: attrib() got an unexpected keyword argument 'convert'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM