CHINESE-OCR
CHINESE-OCR copied to clipboard
crnn pytorch utils data_parallel issue
The angel of this character is: 0 Rotate the array of this img!
AttributeError Traceback (most recent call last)
~/HOLIWORK/CHINESE-OCR/model.py in model(img, model, adjust, detectAngle) 116 text_recs = sort_box(text_recs) 117 # --> 118 result = crnnRec(img, text_recs, model, adjust=adjust) 119 return result, tmp, angle 120
~/HOLIWORK/CHINESE-OCR/model.py in crnnRec(im, text_recs, ocrMode, adjust) 57 sim_pred = ocr(image) 58 else: ---> 59 sim_pred = crnnOcr(image) 60 61 results[index].append(sim_pred) ##识别文字
~/HOLIWORK/CHINESE-OCR/crnn/crnn.py in crnnOcr(image) 75 image = Variable(image) 76 model.eval() ---> 77 preds = model(image) 78 _, preds = preds.max(2) 79 preds = preds.transpose(1, 0).contiguous().view(-1)
~/.local/lib/python3.6/site-packages/torch/nn/modules/module.py in call(self, *input, **kwargs) 545 result = self._slow_forward(*input, **kwargs) 546 else: --> 547 result = self.forward(*input, **kwargs) 548 for hook in self._forward_hooks.values(): 549 hook_result = hook(self, input, result)
~/HOLIWORK/CHINESE-OCR/crnn/models/crnn.py in forward(self, input) 73 def forward(self, input): 74 # conv features ---> 75 conv = utils.data_parallel(self.cnn, input, self.ngpu) 76 b, c, h, w = conv.size() 77 assert h == 1, "the height of conv must be 1"
AttributeError: module 'utils' has no attribute 'data_parallel'
The error is here. Don't know what's wrong, is that my pytorch version?
- Python 3.6.8
- Torch 1.2.0
- Tensorflow 1.7.0
@mangoHoli I met the same error, have you solved it?
I cant find data_parallel in utils. Only me?
@mangoHoli I met the same error, have you solved it?
I forgot how i solved it. But you can check if you got the following code in ‘WORK_PATH/crnn/models/utils.py’:
#!/usr/bin/python
encoding: utf-8
import torch.nn as nn import torch.nn.parallel
def data_parallel(model, input, ngpu): if isinstance(input.data, torch.cuda.FloatTensor) and ngpu > 1: output = nn.parallel.data_parallel(model, input, range(ngpu)) else: output = model(input) return output
I cant find data_parallel in utils. Only me?
I got this in utils.
#!/usr/bin/python
encoding: utf-8
import torch.nn as nn import torch.nn.parallel
def data_parallel(model, input, ngpu): if isinstance(input.data, torch.cuda.FloatTensor) and ngpu > 1: output = nn.parallel.data_parallel(model, input, range(ngpu)) else: output = model(input) return output
@mangoHoli, hello, Have you solved the problem?
@mangoHoli, hello, Have you solved the problem?
hi, have you solved it?