Attribute error when running tuner.search (keras tuner)

I have an issue when I run the function tuner.search from the keras-tuner library. I am trying to tune my hyperparameters but when I call this function, it stops after 3 tries and in each try it is stopped after the first epoch.

I saw someone saying he had also an error when calling tuner.search on windows (I am on a windows machine) but it was due to the name of the file they was giving, I tried this thing but it changed nothing. I don’t know what to do to use this. I also checked if the models were created well and it seems to be the case.

Here is my code :

import pandas as pd
import matplotlib.pyplot as plt

dataframe = pd.read_csv("resultats/resultats11.csv")

var = dataframe.columns.drop(['epidemic peak', 'time to extinction','nombre de noeuds', "nombre d'aretes", 'degre moyen', 'degre minimal', 'degre maximal', 'distance moyenne', 'nombre de smart honeypots', 'nombre de honeypots', 'nombre inf 5', 'nombre res 5'])
X = dataframe[var]
Y = dataframe[['epidemic peak']]

from sklearn.preprocessing import OneHotEncoder, StandardScaler
from sklearn.compose import ColumnTransformer

ct = ColumnTransformer([("PropagationType", OneHotEncoder(), [0])], remainder="passthrough", sparse_threshold=0, verbose=True)
X = ct.fit_transform(X)  ### encodage factice 
sc_x = StandardScaler()
sc_y = StandardScaler()

from sklearn.model_selection import train_test_split

x_train1, x_test, y_train1, y_test = train_test_split(X, Y, test_size=0.15, random_state=1, shuffle=True)
x_train, x_val, y_train, y_val = train_test_split(x_train1, y_train1, test_size=(0.15/0.85), random_state=12, shuffle= True)

x_train = sc_x.fit_transform(x_train)
x_val = sc_x.transform(x_val)
x_test = sc_x.transform(x_test)
y_train = sc_y.fit_transform(y_train)
y_val = sc_y.transform(y_val)
y_test = sc_y.transform(y_test)

from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense
from tensorflow.keras import optimizers
from tensorflow.keras import metrics
import keras_tuner as kt

def create_model(neurons1, neurons2, lr): 
    model = Sequential()
    model.add(Dense(neurons1, input_dim=10, activation='relu'))
    model.add(Dense(neurons2, activation='relu'))
    model.add(Dense(1, activation='relu'))

    model.compile(optimizer=optimizers.Adam(learning_rate=lr), loss = 'mean_absolute_percentage_error', metrics=[metrics.RootMeanSquaredError()])
    return model

def build_model(hp):
    neurons1 = hp.Int("units1", min_value=32, max_value=512, step=32)
    neurons2 = hp.Int("units2", min_value=32, max_value=512, step=32)
    lr = hp.Float("learning_rate", min_value=1e-4, max_value=1e-2, sampling="log")
    model = create_model(neurons1, neurons2, lr)
    return model

import os

tuner = kt.BayesianOptimization(
    build_model,
    objective = 'val_root_mean_squared_error',
    max_trials=20,
    directory=os.path.normpath(r'C:UsersyassiDesktop'),
    overwrite = True)

tuner.search(x_train, y_train, validation_data=(x_val, y_val), epochs = 30, batch_size=32, shuffle=True)

The import are a bit everywhere because I use a jupyter notebook.

And here is the error I have :
Traceback (most recent call last):
File “c:Usersyassi.juliaconda3x86_64libsite-packageskeras_tunersrcenginebase_tuner.py”, line 274, in _try_run_and_update_trial
self._run_and_update_trial(trial, *fit_args, **fit_kwargs)
File “c:Usersyassi.juliaconda3x86_64libsite-packageskeras_tunersrcenginebase_tuner.py”, line 239, in _run_and_update_trial
results = self.run_trial(trial, *fit_args, **fit_kwargs)
File “c:Usersyassi.juliaconda3x86_64libsite-packageskeras_tunersrcenginetuner.py”, line 314, in run_trial
obj_value = self._build_and_fit_model(trial, *args, **copied_kwargs)
File “c:Usersyassi.juliaconda3x86_64libsite-packageskeras_tunersrcenginetuner.py”, line 233, in _build_and_fit_model
results = self.hypermodel.fit(hp, model, *args, **kwargs)
File “c:Usersyassi.juliaconda3x86_64libsite-packageskeras_tunersrcenginehypermodel.py”, line 149, in fit
return model.fit(*args, **kwargs)
File “c:Usersyassi.juliaconda3x86_64libsite-packageskerassrcutilstraceback_utils.py”, line 122, in error_handler
raise e.with_traceback(filtered_tb) from None
File “c:Usersyassi.juliaconda3x86_64libsite-packageskeras_tunersrcenginetuner_utils.py”, line 76, in on_epoch_end
self._save_model()
File “c:Usersyassi.juliaconda3x86_64libsite-packageskeras_tunersrcenginetuner_utils.py”, line 86, in _save_model
self.model.save_weights(write_filepath)
AttributeError: ‘NoneType’ object has no attribute ‘File’

Does anyone have an idea of how to solve this issue or have already met this issue ?

By the way I am using keras_tuner 1.4.7 and tensorflow 2.16.1.

New contributor

kyasz is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật