【发布时间】:2020-08-29 09:05:48
【问题描述】:
我已经问过一个关于这个问题的问题。我只是提供更多细节。我一直在尝试训练我以 Pascal Voc 格式创建的数据集。它是对每个图像中的人行道和背景进行语义分割。我想并且目前正在使用 google colab 中的 Python fastai 库来完成这项任务。当将标记图像传输到输入图像时,我收到错误消息。我需要能够在 fastai 中训练这个数据集。我改编自一个github源代码:https://github.com/keyurparalkar/Semantic-Segmentation-with-UNETs/blob/master/FASTai_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