question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Probelms when fine tuning the models . RuntimeError: inconsistent tensor size

See original GitHub issue

Hello,

l stuck with fine tuning.

1)First of all to fine tune the model you have to set --nh=“256” otherwise it will not work, you’ll get this error

( loading pretrained model from /home/ahmed/Downloads/crnn.pytorch-master/data/crnn.pth Traceback (most recent call last): File “crnn_main.py”, line 98, in <module> crnn.load_state_dict(torch.load(opt.crnn)) File “/home/ahmed/anaconda3/envs/cv/lib/python2.7/site-packages/torch/nn/modules/module.py”, line 335, in load_state_dict own_state[name].copy_(param) RuntimeError: inconsistent tensor size at /py/conda-bld/pytorch_1493676237139/work/torch/lib/TH/generic/THTensorCopy.c:51 )

because the pretrained model --nh=“256” and not 100 as it is set in the default model. But when fine tuning obviously we can change the parameter, so l find it strange that it doesn’t work

  1. tried different configurations while fine tuning the length of the alphabet , nb_classes= 37 ‘0123456789abcdefghijklmnopqrstuvwxyz’ by default

l tried the following : A) add one letter, let’s say Z or another char , . / ‘0123456789abcdefghijklmnopqrstuvwxyzZ’ l got the same error

RuntimeError: inconsistent tensor size at /py/conda-bld/pytorch_1493676237139/work/torch/lib/TH/generic/THTensorCopy.c:51

B) l removed one char and add another remove z and add / ‘0123456789abcdefghijklmnopqrstuvwxy/’

l get the same error

RuntimeError: inconsistent tensor size at /py/conda-bld/pytorch_1493676237139/work/torch/lib/TH/generic/THTensorCopy.c:51

C) l set alphabet only to digits ‘0123456789’

the same error

RuntimeError: inconsistent tensor size at /py/conda-bld/pytorch_1493676237139/work/torch/lib/TH/generic/THTensorCopy.c:51

  1. train a new model with a varibale length alphabet and number of -nh it works perfectly

Have you any idea for solving the problem of fine tuning to make a variable length of alphabet and the architecture ? Thanks a lot

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:16 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
ahmedmazari-dhatimcommented, Jul 1, 2017

Hi, @wulivicte @meijieru

What is the difference between transfer learning with the code of @meijieru as follow :

python2 crnn_main.py --trainroot="train_data/" --valroot="valid_data/" --cuda --adadelta --experiment="sotr_model/" --crnn="data/crnn.pth"

and the code of @wulivicte when you add

 pre_trainmodel = torch.load(opt.crnn)
    model_dict = crnn.state_dict()
    # replace the classfidy layer parameters
   for k,v in model_dict.items():
        if not (k == 'rnn.1.embedding.weight' or k == 'rnn.1.embedding.bias'):
            model_dict[k] = pre_trainmodel[k]

   crnn.load_state_dict(model_dict)
print(crnn)

Then :

python2 crnn_main.py --trainroot="train_data/" --valroot="valid_data/" --cuda --adadelta --experiment="sotr_model/" --crnn="data/crnn.pth"

?

Thank you

0reactions
YoungMiaocommented, Jun 29, 2017

@ahmedmazari-dhatim the train and pre-training model must be the same -nh , i use the -nh = 256 and use the author’s model as a pre-training model

Read more comments on GitHub >

github_iconTop Results From Across the Web

Fine Tuning dimensionality error - machine learning
I am trying to use Resnet50 for image classification problem. However it shows error and I could not fix it. RuntimeError: inconsistent tensor...
Read more >
RuntimeError: inconsistent tensor size - PyTorch Forums
I tried several time but this problem only occurs on 15th epoch. So I guess this is related to illegal format of input...
Read more >
Saving and Loading Models — PyTorch Tutorials 1.0.0 ...
This document provides solutions to a variety of use cases regarding the saving and loading of PyTorch models. Feel free to read the...
Read more >
Errors when fine-tuning T5 - Beginners - Hugging Face Forums
Hi everyone, I'm trying to fine-tune a T5 model. ... each value is a 2d tensor with the first dimension being 3 (your...
Read more >
NVIDIA Deep Learning TensorRT Documentation
It shows how you can take an existing model built with a deep learning ... output tensors of the network - the expected...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found