Что такое "Type Error: can't pickle weakref objects"?

Я пытаюсь pickle.dump() объект со свойством model, который хранит модель Keras и TensorFlow.

admin.py

def build(self, request, queryset):
        count = 0
        for p in queryset:
            if build_id(p.project_management.id):
                count += 1
            else:
                messages.warning(request, f"Could not build model for {p}")
        messages.success(
            request, f"Successfully built models for {count} projects")
    build.short_description = "Build models for selected Projects"

build.py

def build_id(project_id):
    # get directory path to store models in
    path = fetch_model_path(project_id, True)

    # train model
    model, scaler_in, scaler_out = train_project_models(project_id)

    # ensure model was trained
    if model is None:
        return False

    # store models
    store_model(f'{path}/model.pkl', model)
    store_model(f'{path}/scaler_in.pkl', scaler_in)
    store_model(f'{path}/scaler_out.pkl', scaler_out)

    # clear current loaded model from memory
    keras_clear()

    return True

utils.py

# dump model to path
def store_model(path, model):
    with open(path, 'wb') as f:
        model_file = File(f)
        pickle.dump(model, model_file)
        

Когда я построил свою модель, я обнаружил эту ошибку. Я использую проект python Django. enter image description here

Когда я собираю модель, она тоже показывает внутреннюю ошибку сервера, как показано на картинке

enter image description here

Вернуться на верх