• 大小: 63.85MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-07-19
  • 语言: Python
  • 标签:

资源简介

FCN(完全卷积网络)中最简单,最容易使用的pytorch实现

资源截图

代码片段和文件信息

import torch.nn as nn
from torch.utils.data import Dataset DataLoader
from torchvision import transforms
import os
import cv2
import pdb
from onehot import onehot
import torch

transform = transforms.Compose([transforms.ToTensor() transforms.Normalize(mean=[0.485 0.456 0.406] std=[0.229 0.224 0.225])])

class BagDataset(Dataset):

    def __init__(self transform=None):
       self.transform = transform 
    def __len__(self):
       return len(os.listdir(‘last‘))

    def __getitem__(self idx):
        img_name = os.listdir(‘last‘)[idx]
        imgA = cv2.imread(‘last/‘+img_name)
        imgA = cv2.resize(imgA (160 160))
        imgB = cv2.imread(‘last_msk/‘+img_name 0)
        imgB = cv2.resize(imgB (160 160))
        imgB = imgB/255
        imgB = imgB.astype(‘uint8‘)
        imgB = onehot(imgB 2)
        imgB = imgB.swapaxes(0 2).swapaxes(1 2)
        imgB = torch.FloatTensor(imgB)
        #print(imgB.shape)
        if self.transform:
            imgA = self.transform(imgA)    
        item = {‘A‘:imgA ‘B‘:imgB}
        return item

bag = BagDataset(transform)
dataloader = DataLoader(bag batch_size=4 shuffle=True num_workers=4)
if __name__ ==‘__main__‘:
    for batch in dataloader:
        break







 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-08-08 08:35  FCN-pytorch-easiest-master\
     文件        1245  2018-08-08 08:35  FCN-pytorch-easiest-master\BagData.py
     文件       13113  2018-08-08 08:35  FCN-pytorch-easiest-master\FCN.py
     文件        1569  2018-08-08 08:35  FCN-pytorch-easiest-master\README.md
     目录           0  2018-08-08 08:35  FCN-pytorch-easiest-master\checkpoints\
     文件           0  2018-08-08 08:35  FCN-pytorch-easiest-master\checkpoints\None
     目录           0  2018-08-08 08:35  FCN-pytorch-easiest-master\images\
     文件       25211  2018-08-08 08:35  FCN-pytorch-easiest-master\images\task.png
     文件        4821  2018-08-08 08:35  FCN-pytorch-easiest-master\images\vis.png
     文件         456  2018-08-08 08:35  FCN-pytorch-easiest-master\inference.py
     目录           0  2018-08-08 08:35  FCN-pytorch-easiest-master\last\
     文件      125608  2018-08-08 08:35  FCN-pytorch-easiest-master\last\0.jpg
     文件      118467  2018-08-08 08:35  FCN-pytorch-easiest-master\last\10.jpg
     文件      118120  2018-08-08 08:35  FCN-pytorch-easiest-master\last\100.jpg
     文件      291934  2018-08-08 08:35  FCN-pytorch-easiest-master\last\101.jpg
     文件      127769  2018-08-08 08:35  FCN-pytorch-easiest-master\last\102.jpg
     文件       63851  2018-08-08 08:35  FCN-pytorch-easiest-master\last\103.jpg
     文件       71992  2018-08-08 08:35  FCN-pytorch-easiest-master\last\104.jpg
     文件       19206  2018-08-08 08:35  FCN-pytorch-easiest-master\last\105.jpg
     文件       99963  2018-08-08 08:35  FCN-pytorch-easiest-master\last\106.jpg
     文件      491440  2018-08-08 08:35  FCN-pytorch-easiest-master\last\107.jpg
     文件      121964  2018-08-08 08:35  FCN-pytorch-easiest-master\last\108.jpg
     文件       76845  2018-08-08 08:35  FCN-pytorch-easiest-master\last\109.jpg
     文件      316594  2018-08-08 08:35  FCN-pytorch-easiest-master\last\11.jpg
     文件      297693  2018-08-08 08:35  FCN-pytorch-easiest-master\last\110.jpg
     文件      112539  2018-08-08 08:35  FCN-pytorch-easiest-master\last\111.jpg
     文件      114656  2018-08-08 08:35  FCN-pytorch-easiest-master\last\112.jpg
     文件       93629  2018-08-08 08:35  FCN-pytorch-easiest-master\last\113.jpg
     文件       75210  2018-08-08 08:35  FCN-pytorch-easiest-master\last\114.jpg
     文件      142021  2018-08-08 08:35  FCN-pytorch-easiest-master\last\115.jpg
     文件      276155  2018-08-08 08:35  FCN-pytorch-easiest-master\last\116.jpg
............此处省略1052个文件信息

评论

共有 条评论