首页 > 解决方案 > 如何使用 fastai unet_learner?

问题描述

概括

尝试的补救措施

  1. 运行与此处所示相同的过程,没有问题。该过程顺利进行,学习者毫无问题地完成了微调和预测(在camvid_tiny数据集上)。

  2. 检查我处理的数据,包括“标签”、“图像”和“代码”与 camvid 进程中的数据,它们几乎相同(我的 21 个类与 camvid 的 ~30,图像和标签是 256x256 与 camvid 的 96、128) .

  3. dls 中的确认label值不是 0/255(在此处此处注明)

for i in range(len(lnames)):
    y = Image.open(lnames[i])
    y_array = np.array(y)
    print(np.unique(y_array))

[20]
[20]
[20]
[ 5  7  8 11 12 13 14 17 20]
[ 5 12 13 14 15 16 17 20]
...
[14 17 20]
[14 17 20]
[ 8  9 10 11 12 13 14 16 17 19 20]
[ 1  2  3  4  7  8  9 10 11 12 13 14 16 17 18 19 20]
[ 2  3  9 10 12 13 14 16 17 19 20]
[ 1  2  3  4  7  8  9 10 11 12 13 14 16 17 18 19 20]

代码

import os
import json
import numpy as np
from pathlib import Path
from fastai.vision.all import *

>>path = Path(r"D:\EuroSATDS")
>>json_file = r"D:\EuroSATDS\esri_accumulated_stats.json"
>>>with open(json_file, 'r') as f:
    data = json.load(f)
>>>classes = data['Classes']
>>>classes_list = []
>>>classes_value = []
>>>for i in classes:
    x = i['ClassName']
    y = i['ClassValue']
    classes_list.append(x)
    classes_value.append(y)
>>>classes_list[20]
'Palustrine Aquatic Bed'
>>>codes = np.asarray(classes_list, dtype='<U17')
>>>codes
array(['High Intensity De', 'Medium Intensity ', 'Low Intensity Dev',
       'Developed Open Sp', 'Cultivated', 'Pasture/Hay', 'Grassland',
       'Deciduous Forest', 'Evergreen Forest', 'Mixed Forest',
       'Scrub/Shrub', 'Palustrine Forest', 'Palustrine Scrub/',
       'Palustrine Emerge', 'Estuarine Foreste', 'Estuarine Scrub/S',
       'Estuarine Emergen', 'Unconsolidated Sh', 'Bare Land', 'Water'],
      dtype='<U17')
>>fnames = get_image_files(path/"images")
>>fnames[0]
Path('../000000000.jpg')
>>def label_func(fn): return pathB/"labels"/f"{fn.stem}_P.png"
>>dls = SegmentationDataLoaders.from_label_func(pathB, bs=8, fnames = fnames, label_func = label_func, codes = codes)
>>dls.show_batch(max_n=6)

在此处输入图像描述

>> learn = unet_learner(dls, resnet34)
>> learn.fine_tune(1)
IndexError: Target 20 is out of bounds.

IndexError                                Traceback (most recent call last)
~TEMP/ipykernel_14508/3714593663.py in <module>
      2 import time
      3 start = time.time()
----> 4 learn.fine_tune(1)
      5 end = time.time()
      6 print("The time of execution of above program is :", end-start)  

标签: pythondeep-learningpytorchimage-segmentationfast-ai

解决方案


推荐阅读