输出是 ['XXXXXX'] 格式,我怎样才能使它成为 XXXXXX 格式,没有括号和撇号?
letters = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'E', 'H', 'K', 'M', 'O', 'P', 'T', 'X', 'Y']
def decode_batch(out):
ret = []
for j in range(out.shape[0]):
out_best = list(np.argmax(out[j, 2:], 1))
out_best = [k for k, g in itertools.groupby(out_best)]
outstr = ''
for c in out_best:
if c < len(letters):
outstr += letters[c]
ret.append(outstr)
return ret
paths = 'model1_nomer.tflite'
interpreter = tf.lite.Interpreter(model_path=paths)
interpreter.allocate_tensors()
# Get input and output tensors.
input_details = interpreter.get_input_details()
output_details = interpreter.get_output_details()
img = resized
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
img = cv2.resize(img, (128, 64))
img = img.astype(np.float32)
img /= 255
img1 = img.T
img1.shape
X_data1 = np.float32(img1.reshape(1, 128, 64, 1))
input_index = (interpreter.get_input_details()[0]['index'])
interpreter.set_tensor(input_details[0]['index'], X_data1)
interpreter.invoke()
net_out_value = interpreter.get_tensor(output_details[0]['index'])
pred_texts = decode_batch(net_out_value)
if a != pred_texts:
a = pred_texts
print(a)
else:
None
你得到
list
,如果你有一个元素,然后写a[0]
。如果需要显示所有元素,可以写" ".join(a)
我认为您应该使用加入列表方法。
例如,下面的代码:
将以下行输出到控制台: