Comments (4)
在初始化模型之后,先导入模型参数即可。
以 Retinanet-Pytorch/Demo_train.py 文件为例,按照以下修改即可
`
# 初始化模型
net = RetainNet(cfg)
# 这里先导入你的已经训练好的模型权重文件
net.load_state_dict(torch.load("XXX"))
# 将模型移动到gpu上,cfg.DEVICE.MAINDEVICE定义了模型所使用的主GPU
net.to(cfg.DEVICE.MAINDEVICE)
# 初始化训练器,训练器参数通过cfg进行配置;也可传入参数进行配置,但不建议
trainer = Trainer(cfg)
# 训练器开始在 数据集上训练模型
trainer(net, train_dataset)
`
from retinanet-pytorch.
已试成功,非常感谢。那如果训练集类别个数与原先训练的权重类别不一样,那如何抑制后面的几层
from retinanet-pytorch.
由于你类别数都不一样,必须更改模型结构。
你可以这样更改,先初始化模型 -> 导入参数 -> 然后更改模型中的predictor 结构,也就是最后的分类和回归的几层。
这样的做法流程是:
`
# 初始化模型
net = RetainNet(cfg)
# 这里先导入你的已经训练好的模型权重文件
net.load_state_dict(torch.load("XXX"))
# 导入 predictor 结构,并进行初始化。
from Model.struct import predictor
# 将模型中的predictor替换为新的predictor
net.predictor = predictor(num_anchors=anchor数(如果没有更改anchor,那就是9), num_classes=新类别数)
# 将模型移动到gpu上,cfg.DEVICE.MAINDEVICE定义了模型所使用的主GPU
net.to(cfg.DEVICE.MAINDEVICE)
# 初始化训练器,训练器参数通过cfg进行配置;也可传入参数进行配置,但不建议
trainer = Trainer(cfg)
# 训练器开始在 数据集上训练模型
trainer(net, train_dataset)
`
这样做,模型前面的参数均是你训练好的参数,只有predictor 是随机初始化的,你可以使用这种方法进行迁移。
from retinanet-pytorch.
我原本的思路是只改predictor中分类的最后一个卷积层然后训练,但是现在想想那样可能效果并不好,还是应该像你这样,重新训练head部分。
from retinanet-pytorch.
Related Issues (20)
- boxes 矩阵运算报错 IndexError: too many indices for array
- BUG! 当图片(.xml)中不包含任何 object 时! HOT 1
- 如何分别设置输入图片IMAGE_SIZE的长宽? HOT 1
- 迭代次数 HOT 1
- 你好,我用自己的数据集,跑了一夜,loss很低,但是测试结果特别差,能给一些建议吗
- 我训练的数据集,目标比较小,训练的时候loss很低,但是检测不出来,ap值三点几 HOT 3
- 为什么会出现这个错误RuntimeError: Expected object of scalar type float but got scalar type double for argument 'other' HOT 14
- 我计算ap的时候很高有0.83但是检测单张图片为啥没有结果,只有几个框,iou设置为了0.5 HOT 2
- 欢迎大家star、fork
- false positives 特别多的问题 HOT 2
- 报错 HOT 2
- RunTimeError HOT 7
- RuntimeError: Found dtype Double but expected Float HOT 1
- 方便把fpn 的 p6, p7 加回来吗? HOT 1
- fpn最后的3X3卷积都是用的conv1的吗? HOT 2
- VOC数据集的最终mAP HOT 1
- visdom server 網頁無法開啟
- ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (6,) + inhomogeneous part.
- 输入尺寸和预测框大小 HOT 10
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from retinanet-pytorch.