本文整理汇总了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))