@vitalysokolov

Почему в проде (linux) возникает TypeError, а при тесте локально (macos) ее нет?

Помогите найти ошибку )

Есть функция
def encode_single_sample(img_path, label):
    # 1. Read image
    img = tf.io.read_file(img_path)
    # 2. Decode and convert to grayscale
    img = tf.io.decode_png(img, channels=1)
    # 3. Convert to float32 in [0, 1] range
    img = tf.image.convert_image_dtype(img, tf.float32)
    # 4. Resize to the desired size
    img = tf.image.resize(img, [img_height, img_width])
    # 5. Transpose the image because we want the time
    # dimension to correspond to the width of the image.
    img = tf.transpose(img, perm=[1, 0, 2])
    # 6. Map the characters in label to numbers
    label = char_to_num(tf.strings.unicode_split(label, input_encoding="UTF-8"))
    # 7. Return a dict as our model is expecting two inputs
    return {"image": img, "label": label}


Вызываю:
train_dataset = tf.data.Dataset.from_tensor_slices((x_train, y_train))
train_dataset = (
    train_dataset.map(
        encode_single_sample, num_parallel_calls=tf.data.AUTOTUNE
    )
    .batch(batch_size)
    .prefetch(buffer_size=tf.data.AUTOTUNE)
)


Локально на маке все работает, python 3.9
На сервере с linux, python 3.10 вылетает ошибка:

TypeError: in user code:

    File "/srv/solver/kdm/use_model.py", line 75, in encode_single_sample  *
        img = tf.io.read_file(img_path)

    TypeError: Input 'filename' of 'ReadFile' Op has type float64 that does not match expected type of string.


UPD: Помимо этого там простое апи на flask и собственно когда я запускаю flask, он сыпется с этой ошибкой.
На всякий случай, flask запускаю так:
source venv/bin/activate &&
set -a &&
source .env.prod &&
set +a &&

flask --app api run --host=0.0.0.0 -p 5000


UPD2:
Проблема в типе данных:
def encode_single_sample(img_path, label):
    # 1. Read image
    print("img_path", img_path, type(img_path))
    # print("label", img_path, type(label))
    # if type(img_path) is not str:
    #     img_path = str(img_path)
    # if type(label) is not str:
    #     label = str(label)
    img = tf.io.read_file(img_path)
    # 2. Decode and convert to grayscale
    img = tf.io.decode_png(img, channels=1)
    # 3. Convert to float32 in [0, 1] range
    img = tf.image.convert_image_dtype(img, tf.float32)
    # 4. Resize to the desired size
    img = tf.image.resize(img, [img_height, img_width])
    # 5. Transpose the image because we want the time
    # dimension to correspond to the width of the image.
    img = tf.transpose(img, perm=[1, 0, 2])
    # 6. Map the characters in label to numbers
    label = char_to_num(tf.strings.unicode_split(label, input_encoding="UTF-8"))
    # 7. Return a dict as our model is expecting two inputs
    return {"image": img, "label": label}

на линуксе:

print("img_path", img_path, type(img_path)) :

    img_path Tensor("args_0:0", shape=(), dtype=float6
    4) <class 'tensorflow.python.framework.ops.SymbolicTensor'>




на маке:
img_path Tensor("args_0:0", shape=(), dtype=string) <class 'tensorflow.python.framework.ops.SymbolicTensor'>
  • Вопрос задан
  • 49 просмотров
Решения вопроса 1
@vitalysokolov Автор вопроса
UPD:

Solution is this:
img_path = tf.strings.as_string(img_path)
    label = tf.strings.as_string(label)
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы