1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] module.save() Error 'TypeError: this __dict__ descriptor does not support...

Discussão em 'Python' iniciado por Stack, Novembro 29, 2025.

  1. Stack

    Stack Membro Participativo

    I'm following a tutorial on Youtube for image classification with machine learning. I keep getting the error as shown in the title from trying to save a deep learning module with tensorflow.

    I'm using PyCharm on Windows 11.

    here is my code...

    import cv2 as cv
    import numpy as np
    import matplotlib.pyplot as plt
    import tensorflow as tf
    from tensorflow import keras as ker

    (training_images, training_labels), (testing_images, testing_labels) = ker.datasets.cifar10.load_data()
    testing_images, testing_images = training_images / 255, testing_images / 255

    class_names = ['Plane', 'Car', 'Bird', 'Cat', 'Deer', 'Dog', 'Frog', 'Horse', 'Ship', 'Truck']

    for i in range(16):
    plt.subplot(4, 4, i+1)
    plt.xticks([])
    plt.yticks([])
    plt.imshow(training_images, cmap=plt.cm.binary)
    plt.xlabel(class_names[training_labels[0]])

    plt.show()

    training_images = training_images[:20000]
    training_labels = training_labels[:20000]
    testing_images = testing_images[:4000]
    testing_labels = testing_labels[:4000]

    #Model
    model = ker.models.Sequential()
    model.add(ker.layers.Conv2D(32, (3,3), activation='relu', input_shape=(32,32,3)))
    model.add(ker.layers.MaxPooling2D((2,2)))
    model.add(ker.layers.Conv2D(64, (3,3), activation='relu'))
    model.add(ker.layers.MaxPooling2D((2,2)))
    model.add(ker.layers.Conv2D(64, (3,3), activation='relu'))
    model.add(ker.layers.Flatten())
    model.add(ker.layers.Dense(64, activation='relu'))
    model.add(ker.layers.Dense(10, activation='softmax'))

    model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy'])

    model.fit(training_images, training_labels, epochs=1, validation_data=(testing_images, testing_labels))

    loss, accuracy = model.evaluate(testing_images, testing_labels)
    print(f"Loss: {loss}")
    print(f"Accuracy: {accuracy}")

    model.save('img_classifier.model')

    #model = ker.models.load_model()


    the output...

    C:\img_classifier\venv\Scripts\python.exe
    C:\img_classifier\main.py
    625/625 [==============================] - 15s 23ms/step - loss: 2.1824 - accuracy: 0.2874 - val_loss: 2.3014 - val_accuracy: 0.1047
    125/125 [==============================] - 1s 8ms/step - loss: 2.3014 - accuracy: 0.1047
    Loss: 2.30141019821167
    Accuracy: 0.10474999994039536
    WARNING:absl:Found untraced functions such as _jit_compiled_convolution_op, _jit_compiled_convolution_op, _jit_compiled_convolution_op, _update_step_xla while saving (showing 4 of 4). These functions will not be directly callable after loading.
    Traceback (most recent call last):
    File "C:\Users\{user}\PycharmProjects\img_classifier\main.py", line 47, in <module>
    model.save('img_classifier.model')
    File "C:\Users\{user}\AppData\Roaming\Python\Python311\site-packages\keras\utils\traceback_utils.py", line 70, in error_handler
    raise e.with_traceback(filtered_tb) from None
    File "C:\Users\{user}\AppData\Roaming\Python\Python311\site-packages\tensorflow\python\trackable\data_structures.py", line 823, in __getattribute__
    return super().__getattribute__(name)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    TypeError: this __dict__ descriptor does not support '_DictWrapper' objects

    Process finished with exit code 1



    I've tried changing IDE's, originally I was using VSCode but had way more errors, then I switched to PyCharm and this is the only error that persists. As you can see, the code for training the module has no issues, but I cannot save the module afterwards.

    How can I fix this??

    Continue reading...

Compartilhe esta Página