资源简介
用于新冠肺炎胸片扫描,来对新冠肺炎与普通肺炎进行区分
代码片段和文件信息
## 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个文件信息
- 上一篇:手写数字识别
- 下一篇:OpenCV动作识别
相关资源
- 伯努利贝叶斯分类器(BernoulliNB)(
- keras实现cifar-10图片分类
- pima_data.csv印第安人糖尿病数据集
- 随机森林分类(python代码)
- 基于机器学习框架tensorflow的图像分类
- python 叶子分类器 算法
- python MNIST分类 tensorflow
- 使用逻辑回归进行MNIST字符分类识别代
- Fisher线性分类器Python及matalb实现
- 正向最大匹配分词算法及KNN文本分类
- python kNN算法实现MNIST数据集分类 k值
- Python——机器学习实战——AdaBoost分类
- bayes实现水果分类python,包含数据集
- python情感分类
- Python之数据分析 - 2019年4月税收分类编
- Alexnet鲜花分类
- 机器学习经典分类算法
- tensorflow物体检测-图片目标分类计数
- pytorch的cifar10数据集分类程序
- 朴素贝叶斯分类原理及Python实现简单
- 朴素贝叶斯文本分类的Python实现代码
- python+tensorflow+keras 基于Inception-v3模型
评论
共有 条评论