xiaofengShi / CHINESE-OCR

[python3.6] 运用tf实现自然场景文字检测,keras/pytorch实现ctpn+crnn+ctc实现不定长场景文字OCR识别
2.9k stars 956 forks source link

crnn pytorch utils data_parallel issue #120

Open mangoHoli opened 4 years ago

mangoHoli commented 4 years ago

The angel of this character is: 0 Rotate the array of this img!

AttributeError Traceback (most recent call last)

in 2 img = np.array(im.convert('RGB')) 3 t = time.time() ----> 4 result,img,angle = model.model(img,model='crnn', detectAngle=True) ## if model == crnn ,you should install pytorch 5 print( "It takes time:{}s".format(time.time()-t)) 6 print( "---------------------------------------") ~/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
VictorYang097 commented 4 years ago

@mangoHoli I met the same error, have you solved it?

yyr6661 commented 4 years ago

I cant find data_parallel in utils. Only me?

mangoHoli commented 4 years ago

@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

mangoHoli commented 4 years ago

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

vance-coder commented 4 years ago

@mangoHoli, hello, Have you solved the problem?

dadadadashan commented 4 years ago

@mangoHoli, hello, Have you solved the problem?

hi, have you solved it?