准备创建的数据集的语义分割,使用fastai在谷歌的colab

问题描述 投票:0回答:1

我已经问过一个关于这个问题的问题。我只是提供更多的细节。我一直在尝试训练一个我以Pascal Voc格式创建的数据集。它是人行道和背景的语义分割,在每个图像。我想并且目前正在使用google colab中的Python fastai库来完成这个任务。当它的时间转移标签图像到输入图像,我得到错误信息。我需要能够在fastai中训练这个数据集。我是从一个github的源码中改编的。https:/github.comkeyurparalkarSemantic-Segmentation-with-UNETsblobmasterFASTai_UNET.ipynb。

%reload_ext autoreload
%autoreload 2
%matplotlib inline

import fastai
from fastai import *
from fastai.vision import*

path = '/content/drive/My Drive/Umes2020'
image_ip = path + '/JPEGImages'
images_lbl = path + '/SegmentationClassPNG'
codes = np.array(["background","Sidewalk"])
keep_train_val = path + '/val.txt'
class SegmentationProcessor(PreProcessor):
    "`PreProcessor` that stores the classes for segmentation."
    def __init__(self, ds:ItemList): self.classes = ds.classes
    def process(self, ds:ItemList):  ds.classes,ds.c = self.classes,len(self.classes)
class SegmentationLabelList(ImageList):
    "`ItemList` for segmentation masks."
    _processor=SegmentationProcessor
    def __init__(self, items:Iterator, classes:Collection=None, **kwargs):
        super().__init__(items, **kwargs)
        self.classes,self.loss_func = classes,CrossEntropyFlat(axis=1)

    def new(self, items, classes=None, **kwargs):
        return self.new(items, ifnone(classes, self.classes), **kwargs)

    def open(self, fn): return open_mask(fn,convert_mode='P')   #HERE
    def analyze_pred(self, pred, thresh:float=0.5): return pred.argmax(dim=0)[None]
    def reconstruct(self, t:Tensor): return ImageSegment(t)
class SegmentationItemList(ImageList):
    "`ItemList` suitable for segmentation tasks."
    _label_cls,_square_show_res = SegmentationLabelList,False
get_y_fn = lambda x: images_lbl/f'{x.stem}.png'
data = (SegmentationItemList.from_folder(image_ip)
        .split_by_rand_pct()
        .label_from_func(get_y_fn,classes=codes)
        .transform(get_transforms(),size=128,tfm_y=True)
        .databunch(bs=4))
#          .normalize(imagenet_stats))
TypeError                                 Traceback (most recent call last)
<ipython-input-11-e9a537d7b20e> in <module>()
      1 data = (SegmentationItemList.from_folder(image_ip)
      2         .split_by_rand_pct()
----> 3         .label_from_func(get_y_fn,classes=codes)
      4         .transform(get_transforms(),size=128,tfm_y=True)
      5         .databunch(bs=4))

3 frames
<ipython-input-10-2728937c21a8> in <lambda>(x)
----> 1 get_y_fn = lambda x: images_lbl/f'{x.stem}.png'

TypeError: unsupported operand type(s) for /: 'str' and 'str'
python deep-learning computer-vision object-detection image-segmentation
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.