1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Python] TypeError: Can't convert object to 'str' for 'filename'

Discussão em 'Python' iniciado por Stack, Outubro 25, 2024 às 13:12.

  1. Stack

    Stack Membro Participativo

    I want to create imgs variable to load all the images in "./input/hubmap-organ-segmentation/train_images/" folder. My code raised TypeError: Can't convert object to 'str' for 'filename' error.

    import os
    import glob
    import pandas as pd
    import cv2

    BASE_PATH = "./input/hubmap-organ-segmentation/"
    df = pd.read_csv(os.path.join(BASE_PATH, "train.csv"))

    all_image_files = glob.glob(os.path.join(BASE_PATH, "train_images", "**", "*.tiff"), recursive=True)
    train_img_map = {int(x[:-5].rsplit("/", 1)[-1]):x for x in all_image_files}
    df.insert(3, "img_path", image_ids.map(train_img_map))

    imgs = [cv2.imread(img_path)[..., ::-1] for img_path in df.img_path.values]


    Traceback:

    ---------------------------------------------------------------------------
    TypeError Traceback (most recent call last)
    Input In [132], in <cell line: 38>()
    37 ftu_crop_map = {}
    38 for _organ in ORGANS:
    39 #sub_df = df[df.organ==_organ].sample(N_EX)
    ---> 40 imgs = [cv2.imread(img_path)[..., ::-1] for img_path in df.img_path.values]

    Input In [132], in <listcomp>(.0)
    37 ftu_crop_map = {}
    38 for _organ in ORGANS:
    39 #sub_df = df[df.organ==_organ].sample(N_EX)
    ---> 40 imgs = [cv2.imread(img_path)[..., ::-1] for img_path in df.img_path.values]

    TypeError: Can't convert object to 'str' for 'filename'


    Example of img_path:

    df.img_path[0]
    './input/hubmap-organ-segmentation/train_images/10044.tiff'

    Continue reading...

Compartilhe esta Página