代码之家  ›  专栏  ›  技术社区  ›  Extra_Caterpillar

我面临着使用白蛋白增强图像的问题

  •  0
  • Extra_Caterpillar  · 技术社区  · 2 年前

    我是深度学习和计算机视觉的新手。我最近做了一个关于yolov1实现的教程。现在我正在用不同的数据集进行尝试。

    这是我的代码-

    def get_bboxes(filename):
      name = filename[:-4]
      indices = meta_df[meta_df['new_img_id'] == float(name)]
      bounding_boxes = []
      for index, row in indices.iterrows():
        x = float(row['x'])
        y = float(row['y'])
        w = float(row['width'])
        h = float(row['height'])
        im_w = float(row['img_width'])
        im_h = float(row['img_height'])
        class_id = int(row['cat_id'])
        bounding_box = [(x+w/2)/(im_w), (y+h/2)/(im_h), w/im_w, h/im_h, class_id]
        bounding_boxes.append(bounding_box)
      return tf.convert_to_tensor(bounding_boxes, dtype=tf.float32)
    
    def generate_output(bounding_boxes):
      output_label = np.zeros([int(SPLIT_SIZE), int(SPLIT_SIZE), int(N_CLASSES+5)])
      for b in range(len(bounding_boxes)):
        grid_x = bounding_boxes[...,b,0]*SPLIT_SIZE
        grid_y = bounding_boxes[...,b,1]*SPLIT_SIZE
    
        i = int(grid_x)
        j = int(grid_y)
    
        output_label[i, j, 0:5] = [1., grid_x%1, grid_y%1, bounding_boxes[...,b,2], bounding_boxes[...,b,3]]
        output_label[i, j, 5+int(bounding_boxes[...,b,4])] = 1.
    
      return tf.convert_to_tensor(output_label, tf.float32)
    
    def get_imboxes(im_path, map):
      img = tf.io.decode_jpeg(tf.io.read_file('./new_dataset/'+im_path))
      img = tf.cast(tf.image.resize(img, [H,W]), dtype=tf.float32)
    
      bboxes = tf.numpy_function(func=get_bboxes, inp=[im_path], Tout=tf.float32)
    
      return img, bboxes
    
    train_ds2 = train_ds1.map(get_imboxes)
    val_ds2 = val_ds1.map(get_imboxes)
    
    transforms = A.Compose([
        A.Resize(H,W),
        A.RandomCrop(
            width = np.random.randint(int(0.9*W), W),
            height = np.random.randint(int(0.9*H), H), p=0.5),
        A.RandomScale(scale_limit=0.1, interpolation=cv.INTER_LANCZOS4, p=0.5),
        A.HorizontalFlip(p=0.5),
        A.Resize(H,W)
    ], bbox_params =A.BboxParams(format='yolo'))
    
    def aug_albument(image, bboxes):
      augmented = transforms(image = image, bboxes = bboxes)
      return [tf.convert_to_tensor(augmented['image'], dtype=tf.float32), tf.convert_to_tensor(augmented['bboxes'], dtype=tf.float32)]
    
    def process_data(image, bboxes):
      aug = tf.numpy_function(func=aug_albument, inp=[image, bboxes], Tout=(tf.float32, tf.float32))
      return aug[0], aug[1]
    
    train_ds3 = train_ds2.map(process_data)
    

    我在蛋白表上弄错了。

    当我写这些行的时候-

    for i, j in train_ds3:
      print(j)
    

    我收到这个错误- InvalidArgumentError: {{function_node __wrapped__IteratorGetNext_output_types_2_device_/job:localhost/replica:0/task:0/device:CPU:0}} ValueError: Expected y_min for bbox (0.203125, -0.002777785062789917, 0.8187500238418579, 0.8694444596767426, 5.0) to be in the range [0.0, 1.0], got -0.002777785062789917. 我检查了train_ds2的所有标签。但我找不到任何负值。我在这里错过了什么?

    我试着在图片上评论所有的相册操作,但仍然存在相同的问题

    0 回复  |  直到 2 年前
        1
  •  0
  •   LetsTryMySolution    2 年前

    在get_bboxes()函数中,您将获得如下值: x = float(row['x']) y = float(row['y']) w = float(row['width']) h = float(row['height']) 当您检索形式为x,y,w,h的数据时,这意味着它已经是x_center和y_center了。所以当你这样做的时候 (x+w/2)/(im_w) 甚至 (y+h/2)/(im_h) ,它计算x_max和y_max。格式将不正确,在此之前,您在中不会有任何问题 train_ds2 。当您将白蛋白与一起使用时,会出现问题 format='yolo' 。它将接收不正确的格式,这可能是负值的原因。

    我认为解决方案是修改您的 get_bboxes() 功能如下:

    bounding_box = [x/im_w, y/im_h, w/im_w, h/im_h, class_id]
    

    我不知道你的数据格式,所以如果我错了,请提供更多关于所用格式的详细信息。