Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

运行demo用cenn.pth预训练模型显示Expected 512, got 64 #71

Open
whistbibi opened this issue Nov 8, 2021 · 0 comments
Open

运行demo用cenn.pth预训练模型显示Expected 512, got 64 #71

whistbibi opened this issue Nov 8, 2021 · 0 comments

Comments

@whistbibi
Copy link

我改了在cpu上运行和去掉covert(‘L’)
model = model.cuda()

print('loading pretrained model from %s' % model_path)

if params.multi_gpu:

model = torch.nn.DataParallel(model)
checkpoint =torch.load(model_path, map_location=torch.device('cpu'))
model.load_state_dict(checkpoint,False)

converter = utils.strLabelConverter(params.alphabet)

transformer = dataset.resizeNormalize((100, 32))

image = Image.open(image_path).convert('L')

image = Image.open(image_path)
image = transformer(image)
if torch.cuda.is_available():
image = image.cuda()

image = image.view(1, *image.size())
image = Variable(image)

log:

`CRNN(
(cnn): Sequential(
(conv0): Conv2d(3, 64, kernel_size=(5, 5), stride=(2, 2), padding=(2, 2))
(relu0): ReLU(inplace=True)
(pooling0): MaxPool2d(kernel_size=3, stride=2, padding=0, dilation=1, ceil_mode=False)
(conv1): Conv2d(64, 32, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
(relu1): ReLU(inplace=True)
(conv2): Conv2d(32, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
(batchnorm2): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(relu2): ReLU(inplace=True)
(conv3): Conv2d(64, 32, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
(pooling2): MaxPool2d(kernel_size=(2, 2), stride=(2, 1), padding=(0, 1), dilation=1, ceil_mode=False)
(conv4): Conv2d(32, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
(batchnorm4): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(conv5): Conv2d(64, 32, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
(pooling3): MaxPool2d(kernel_size=(2, 2), stride=(2, 1), padding=(0, 1), dilation=1, ceil_mode=False)
(conv6): Conv2d(32, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
(batchnorm6): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
)
(rnn): Sequential(
(0): BidirectionalLSTM(
(rnn): LSTM(512, 256, bidirectional=True)
(embedding): Linear(in_features=512, out_features=256, bias=True)
)
(1): BidirectionalLSTM(
(rnn): LSTM(256, 256, bidirectional=True)
(embedding): Linear(in_features=512, out_features=204, bias=True)
)
)
)
loading pretrained model from ./path/to/crnn.pth

Traceback (most recent call last):
File "demo.py", line 45, in
preds = model(image)
File "/usrhome/jingli/.conda/envs/202110-crnn-License-plate-env/lib/python3.6/site-packages/torch/nn/modules/module.py", line 532, in call
result = self.forward(*input, **kwargs)
File "/usrhome/jingli/.conda/envs/202110-crnn-License-plate-env/lib/python3.6/site-packages/torch/nn/parallel/data_parallel.py", line 140, in forward
return self.module(*inputs, **kwargs)
File "/usrhome/jingli/.conda/envs/202110-crnn-License-plate-env/lib/python3.6/site-packages/torch/nn/modules/module.py", line 532, in call
result = self.forward(*input, **kwargs)
File "/dm10801/B1_tinyAI_project/202110-cruiser/1.1creat_pytorch_module/models/crnn.py", line 87, in forward
output = self.rnn(conv)
File "/usrhome/jingli/.conda/envs/202110-crnn-License-plate-env/lib/python3.6/site-packages/torch/nn/modules/module.py", line 532, in call
result = self.forward(*input, **kwargs)
File "/usrhome/jingli/.conda/envs/202110-crnn-License-plate-env/lib/python3.6/site-packages/torch/nn/modules/container.py", line 100, in forward
input = module(input)
File "/usrhome/jingli/.conda/envs/202110-crnn-License-plate-env/lib/python3.6/site-packages/torch/nn/modules/module.py", line 532, in call
result = self.forward(*input, **kwargs)
File "/dm10801/B1_tinyAI_project/202110-cruiser/1.1creat_pytorch_module/models/crnn.py", line 14, in forward
recurrent, _ = self.rnn(input)
File "/usrhome/jingli/.conda/envs/202110-crnn-License-plate-env/lib/python3.6/site-packages/torch/nn/modules/module.py", line 532, in call
result = self.forward(*input, **kwargs)
File "/usrhome/jingli/.conda/envs/202110-crnn-License-plate-env/lib/python3.6/site-packages/torch/nn/modules/rnn.py", line 556, in forward
self.check_forward_args(input, hx, batch_sizes)
File "/usrhome/jingli/.conda/envs/202110-crnn-License-plate-env/lib/python3.6/site-packages/torch/nn/modules/rnn.py", line 508, in check_forward_args
self.check_input(input, batch_sizes)
File "/usrhome/jingli/.conda/envs/202110-crnn-License-plate-env/lib/python3.6/site-packages/torch/nn/modules/rnn.py", line 159, in check_input
self.input_size, input.size(-1)))
RuntimeError: input.size(-1) must be equal to input_size. Expected 512, got 64`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant