Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: module 'keras.utils' has no attribute 'get_file' #74

Open
TDL77 opened this issue Jun 26, 2022 · 1 comment
Open

AttributeError: module 'keras.utils' has no attribute 'get_file' #74

TDL77 opened this issue Jun 26, 2022 · 1 comment

Comments

@TDL77
Copy link

TDL77 commented Jun 26, 2022

-- for keras
from classification_models.keras import Classifiers

--передаю как np.array ...images
ResNet18, preprocess_input = Classifiers.get('resnet18')

X = preprocess_input(images)

--prepare your data
--Split the loaded dataset into train, test sets
X_train, X_test, y_train, y_test = train_test_split(X, labels,
test_size = 0.2,
random_state = random_seed ,
stratify = labels)

print("x_train shape = ",X_train.shape)
print("y_train shape = ",y_train.shape)
print("\nx_test shape = ",X_test.shape)
print("y_test shape = ",y_test.shape)

--x_train shape = (9754, 180, 180, 3)
--y_train shape = (9754,)
--x_test shape = (2439, 180, 180, 3)
--y_test shape = (2439,)

n_classes = 40

--build model
base_model = ResNet18(input_shape=(sz,sz,3), weights='imagenet', include_top=False)
x = keras.layers.GlobalAveragePooling2D()(base_model.output)
output = keras.layers.Dense(n_classes, activation='softmax')(x)
model = keras.models.Model(inputs=[base_model.input], outputs=[output])

--train
model.compile(optimizer='SGD', loss='categorical_crossentropy', metrics=['accuracy'])

history = model.fit(x_train, y_train,
epochs=100,
batch_size=32,
validation_data = (x_test, y_test)
callbacks=[callbacks],
class_weight=class_weights
)
...и вот дальше вылазит эта ошибка
AttributeError: module 'keras.utils' has no attribute 'get_file'

...подскажи а можно передать через ?
train_generator = train_datagen.flow_from_directory( base_path,
target_size=(sz,sz),..............

@KinzangDorji66
Copy link

I encountered the same error and It was because the weights parameter was explicitly assigned to imagenet while calling the ResNet18 model. As per documentation, the pretrained imagenet weights are set as default for the model if not set to None. @TDL77

https://stackoverflow.com/questions/68032028/attributeerror-module-keras-utils-has-no-attribute-get-file-using-classific

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants