CHINESE-OCR icon indicating copy to clipboard operation
CHINESE-OCR copied to clipboard

crnn pytorch utils data_parallel issue

Open mangoHoli opened this issue 5 years ago • 6 comments

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

mangoHoli avatar Sep 18 '19 03:09 mangoHoli

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

VictorYang097 avatar Feb 08 '20 02:02 VictorYang097

I cant find data_parallel in utils. Only me?

yyr6661 avatar Mar 21 '20 07:03 yyr6661

@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 avatar Mar 23 '20 00:03 mangoHoli

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 avatar Mar 23 '20 00:03 mangoHoli

@mangoHoli, hello, Have you solved the problem?

vance-coder avatar Apr 17 '20 18:04 vance-coder

@mangoHoli, hello, Have you solved the problem?

hi, have you solved it?

dadadadashan avatar Apr 28 '20 14:04 dadadadashan