本文整理匯總了Python中utils.strLabelConverter方法的典型用法代碼示例。如果您正苦於以下問題:Python utils.strLabelConverter方法的具體用法?Python utils.strLabelConverter怎麽用?Python utils.strLabelConverter使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類utils
的用法示例。
在下文中一共展示了utils.strLabelConverter方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: predict_this_box
# 需要導入模塊: import utils [as 別名]
# 或者: from utils import strLabelConverter [as 別名]
def predict_this_box(image, model, alphabet):
converter = utils.strLabelConverter(alphabet)
transformer = dataset.resizeNormalize((200, 32))
image = transformer(image)
if torch.cuda.is_available():
image = image.cuda()
image = image.view(1, *image.size())
image = Variable(image)
model.eval()
preds = model(image)
_, preds = preds.max(2)
preds = preds.transpose(1, 0).contiguous().view(-1)
preds_size = Variable(torch.IntTensor([preds.size(0)]))
raw_pred = converter.decode(preds.data, preds_size.data, raw=True)
sim_pred = converter.decode(preds.data, preds_size.data, raw=False)
print('%-30s => %-30s' % (raw_pred, sim_pred))
return sim_pred
示例2: crnn_recognition
# 需要導入模塊: import utils [as 別名]
# 或者: from utils import strLabelConverter [as 別名]
def crnn_recognition(cropped_image, model):
converter = utils.strLabelConverter(alphabet)
image = cropped_image.convert('L')
##
# w = int(image.size[0] / (280 * 1.0 / 160))
transformer = dataset.resizeNormalize((280, 32))
image = transformer(image)
# if torch.cuda.is_available():
# image = image.cuda()
image = image.view(1, *image.size())
image = Variable(image)
model.eval()
preds = model(image)
_, preds = preds.max(2)
preds = preds.transpose(1, 0).contiguous().view(-1)
preds_size = Variable(torch.IntTensor([preds.size(0)]))
sim_pred = converter.decode(preds.data, preds_size.data, raw=False)
print('results: {0}'.format(sim_pred))
return sim_pred
示例3: checkConverter
# 需要導入模塊: import utils [as 別名]
# 或者: from utils import strLabelConverter [as 別名]
def checkConverter(self):
encoder = utils.strLabelConverter('abcdefghijklmnopqrstuvwxyz')
# Encode
# trivial mode
result = encoder.encode('efa')
target = (torch.IntTensor([5, 6, 1]), torch.IntTensor([3]))
self.assertTrue(equal(result, target))
# batch mode
result = encoder.encode(['efa', 'ab'])
target = (torch.IntTensor([5, 6, 1, 1, 2]), torch.IntTensor([3, 2]))
self.assertTrue(equal(result, target))
# Decode
# trivial mode
result = encoder.decode(
torch.IntTensor([5, 6, 1]), torch.IntTensor([3]))
target = 'efa'
self.assertTrue(equal(result, target))
# replicate mode
result = encoder.decode(
torch.IntTensor([5, 5, 0, 1]), torch.IntTensor([4]))
target = 'ea'
self.assertTrue(equal(result, target))
# raise AssertionError
def f():
result = encoder.decode(
torch.IntTensor([5, 5, 0, 1]), torch.IntTensor([3]))
self.assertRaises(AssertionError, f)
# batch mode
result = encoder.decode(
torch.IntTensor([5, 6, 1, 1, 2]), torch.IntTensor([3, 2]))
target = ['efa', 'ab']
self.assertTrue(equal(result, target))