0

Вывод происходит в формате ['XXXXXX'], как сделать чтобы он был в формате XXXXX, без скобок и опострофов?

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
1

2 ответа 2

3

У вас выводится list, если у вас в нём один элемент, то напишите a[0]. Если вам надо вывести все элементы, можете написать " ".join(a)

2

Думаю, что Вам следует использовать метод списка join.

Например, следующий код:

numList = ['1', '2', '3', '4'] 
print(' ' .join(numList))

Выведет в консоль строку:

1 2 3 4

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.