Comments (5)
Hi @zihaozhihao, Sorry for the late reply. Let's start to analyze the problem.
First, the error is quite expected, because you are creating a model with 100 classes and trying to load weights from a model with 1000 classes.
Secondly, there is no universal case for modifying models. There are at least two typical tasks: re-training a classifier (for fine-tuning) and forming a feature extractor (e.g. for segmentation).
If you want to change the number of classes in the model, you can do this:
from kerascv.model_provider import get_model as kecv_get_model
import numpy as np
import keras
net = kecv_get_model("resnet50", pretrained=True)
x2 = net.get_layer("output").input
x2 = keras.layers.Dense(units=100, name="output")(x2)
net2 = keras.models.Model(inputs=net.input, outputs=x2)
x = np.zeros((1, 224, 224, 3), np.float32)
y = net2.predict(x)
assert (y.shape == (1, 100))
If you want to get the pretrained feature extractor (without aggregation layer):
from kerascv.model_provider import get_model as kecv_get_model
import numpy as np
import keras
net = kecv_get_model("resnet50", pretrained=True)
x2 = net.get_layer("features/final_pool").input
net2 = keras.models.Model(inputs=net.input, outputs=x2)
net2.summary()
from imgclsmob.
I don't know what might be the problem here, but I think you can try a different approach to create your model, i.e. you should only take layers up to the second last layer and then add your own Dense Layer with the number of classes you want.
from imgclsmob.
Yes, there are many hack ways to fix this problem. But if so, there is no need to add classes=1000
this argument. Most of situations, our own dataset is unlikely to have exactly 1000 classes. Just suggestion.
from imgclsmob.
from imgclsmob.
Thanks for replying and that definitely works!
from imgclsmob.
Related Issues (20)
- API
- Inplace RunError when testing backward of RevNet with PyTorch 1.11.0 HOT 1
- [PyTorch] simplepose_resnet18_coco model weights loading error
- [Pytorch] Could you provide the hyper-parameters for the model training on Pascal VOC dataset?
- Adding new SOTA backbones
- Issue while using seresnet HOT 1
- (tf)Resnesta model problems HOT 12
- demo_pt.py failed on ICNet HOT 4
- Error in PSPBlock while running inference with ICNet HOT 2
- Problem when loading CGNet HOT 3
- Looking forward to the <nfnets> researched by deepmind
- 'seresnext50_32x4d' pytorch RuntimeError: Given input size: (2048x4x4). Calculated output size: (2048x-2x-2). Output size is too small HOT 1
- Multiple outputs using PSPNet pre-trained model on Cityscapes HOT 7
- VoVNet27s Model Weights Missing HOT 1
- Performance issues in your project (by P3) HOT 1
- Visual Transformers?
- VGG models for cifar
- pytorchcv in_size argument
- PyramidNet maybe wrong.
- Support the XDG Base Directory Specification
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 imgclsmob.