• 大小: 0.81M
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-04-15
  • 语言: Python
  • 标签: 新冠  肺炎  分类  covid  

资源简介

用于新冠肺炎胸片扫描,来对新冠肺炎与普通肺炎进行区分

资源截图

代码片段和文件信息

## The code below gives you Flatten and the double Adaptive Pooling (from fastai) plus
## a viable head. You must fill the number of FC‘s nodes manually through the myhead function
from torch import Tensor
from torch import nn
import torch
import torchvision
import logging as log
from typing import Optional # required for “Optional[type]“

class Flatten(nn.Module):
    “Flatten ‘x‘ to a single dimension often used at the end of a model. ‘full‘ for rank-1 tensor“
    def __init__(self full:bool=False):
        super().__init__()
        self.full = full

    def forward(self x):
        return x.view(-1) if self.full else x.view(x.size(0) -1)

class AdaptiveConcatPool2d(nn.Module):
    “layer that concats ‘AdaptiveAvgPool2d‘ and ‘AdaptiveMaxPool2d‘.“ # from pytorch
    def __init__(self sz:Optional[int]=None): 
        “Output will be 2*sz or 2 if sz is None“
        super().__init__()
        self.output_size = sz or 1
        self.ap = nn.AdaptiveAvgPool2d(self.output_size)
        self.mp = nn.AdaptiveMaxPool2d(self.output_size)
    def forward(self x): return torch.cat([self.mp(x) self.ap(x)] 1)
    
def myhead(nf nc):
    return \
    nn.Sequential(        # the dropout is needed otherwise you cannot load the weights
            AdaptiveConcatPool2d()
            Flatten()
            nn.BatchNorm1d(nfeps=1e-05momentum=0.1affine=Truetrack_running_stats=True)
            nn.Dropout(p=0.25inplace=False)
            nn.Linear(nf 512bias=True)
            nn.ReLU(True)
            nn.BatchNorm1d(512eps=1e-05momentum=0.1affine=Truetrack_running_stats=True)
            nn.Dropout(p=0.5inplace=False)
            nn.Linear(512 ncbias=True)
        )


my_model=torchvision.models.resnet50() 
modules=list(my_model.children())
modules.pop(-1) 
modules.pop(-1) 
temp=nn.Sequential(nn.Sequential(*modules))
tempchildren=list(temp.children()) 
#append the special fastai head
#Configured according to Model Architecture

tempchildren.append(myhead(40962))
model_r50=nn.Sequential(*tempchildren)

state = torch.load(path+‘Corona_model_stage5.pth‘)
model_r50.load_state_dict(state[‘model‘])

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2020-05-31 09:15  COVID-19-Scanner-master\
     文件       10244  2020-05-20 14:33  COVID-19-Scanner-master\.DS_Store
     文件          29  2020-05-20 14:33  COVID-19-Scanner-master\.gitignore
     文件        1075  2020-05-20 14:33  COVID-19-Scanner-master\LICENSE.md
     文件        2198  2020-05-20 14:33  COVID-19-Scanner-master\Pytorch-Covid.py
     文件        3376  2020-05-20 14:33  COVID-19-Scanner-master\README.md
     目录           0  2020-05-29 19:26  COVID-19-Scanner-master\app\
     文件       10244  2020-05-20 14:33  COVID-19-Scanner-master\app\.DS_Store
     文件        5299  2020-05-20 14:33  COVID-19-Scanner-master\app\app.py
     文件          49  2020-05-20 14:33  COVID-19-Scanner-master\app\covid_model.json
     目录           0  2020-05-29 19:26  COVID-19-Scanner-master\app\frontend\
     文件         310  2020-05-20 14:33  COVID-19-Scanner-master\app\frontend\.gitignore
     文件        2891  2020-05-20 14:33  COVID-19-Scanner-master\app\frontend\README.md
     文件      583979  2020-05-20 14:33  COVID-19-Scanner-master\app\frontend\package-lock.json
     文件         922  2020-05-20 14:33  COVID-19-Scanner-master\app\frontend\package.json
     目录           0  2020-05-29 19:26  COVID-19-Scanner-master\app\frontend\public\
     文件        3150  2020-05-20 14:33  COVID-19-Scanner-master\app\frontend\public\favicon.ico
     文件        1721  2020-05-20 14:33  COVID-19-Scanner-master\app\frontend\public\index.html
     文件        5347  2020-05-20 14:33  COVID-19-Scanner-master\app\frontend\public\logo192.png
     文件        9664  2020-05-20 14:33  COVID-19-Scanner-master\app\frontend\public\logo512.png
     文件         492  2020-05-20 14:33  COVID-19-Scanner-master\app\frontend\public\manifest.json
     文件          67  2020-05-20 14:33  COVID-19-Scanner-master\app\frontend\public\robots.txt
     目录           0  2020-05-29 19:26  COVID-19-Scanner-master\app\frontend\src\
     目录           0  2020-05-29 19:26  COVID-19-Scanner-master\app\frontend\src\actions\
     文件         650  2020-05-20 14:33  COVID-19-Scanner-master\app\frontend\src\actions\index.js
     目录           0  2020-05-29 19:26  COVID-19-Scanner-master\app\frontend\src\api\
     文件          96  2020-05-20 14:33  COVID-19-Scanner-master\app\frontend\src\api\images.js
     目录           0  2020-05-29 19:26  COVID-19-Scanner-master\app\frontend\src\components\
     文件         862  2020-05-20 14:33  COVID-19-Scanner-master\app\frontend\src\components\App.js
     文件        1618  2020-05-20 14:33  COVID-19-Scanner-master\app\frontend\src\components\Header.js
     文件        1594  2020-05-20 14:33  COVID-19-Scanner-master\app\frontend\src\components\Login.js
............此处省略22个文件信息

评论

共有 条评论