[Python] TypeError: 'BatchDataset' object is not subscriptable

Discussão em 'Python' iniciado por Stack, Abril 26, 2025.

  1. Stack

    Stack Membro Participativo

    plt.figure(figsize = (15,15))
    # data_files.take(count) : Creates a Dataset with at most 'count' elements(batch) from the dataset
    for image, label in data_files.take(1):
    for i in range(12):
    plt.subplot(3, 4,i+1) # many plots at a time =>subpots
    plt.imshow(image.numpy().astype('uint8')) #converting all data of image into numpy and than to integer type as they were in float.
    plt.title(data_files[label]) # title of the class_name of image
    plt.axis("off") # Hide the values of graph


    The output is:

    ypeError Traceback (most recent call last)
    <ipython-input-87-e6bd849f1b25> in <module>
    6 plt.subplot(3, 4,i+1) # many plots at a time =>subpots
    7 plt.imshow(image.numpy().astype('uint8')) #converting all data of image into numpy and than to integer type as they were in float.
    ----> 8 plt.title(data_files[label]) # title of the class_name of image
    9 plt.axis("off") # Hide the values of graph
    10

    TypeError: 'BatchDataset' object is not subscriptable


    Please, how can I fix this problem?

    Continue reading...

Compartilhe esta Página