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

Fix cloning with compiled sequential model #20888

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Surya2k1
Copy link
Contributor

@Surya2k1 Surya2k1 commented Feb 9, 2025

Currently cloning of model is not considering compiled config.

As reported in #20884, the minimal code snippet is as follows.

from keras.layers import Dense, Input
from keras.models import Sequential, clone_model
clf = Sequential()
clf.add(Input((7,)))
clf.add(Dense(8, activation="relu"))
clf.add(Dense(1, activation="sigmoid"))
clf.compile(optimizer="adam", loss="binary_crossentropy", metrics=["accuracy"])
print("Original compiled?", clf.compiled)
cloned = clone_model(clf)
print("Cloned compiled?", cloned.compiled)

Added a fix for Sequential model and Functional model also.

Fixes #20884 .

Similar issue #20876

@codecov-commenter
Copy link

codecov-commenter commented Feb 9, 2025

Codecov Report

Attention: Patch coverage is 62.50000% with 3 lines in your changes missing coverage. Please review.

Project coverage is 82.24%. Comparing base (b9a49ea) to head (5d9cdb8).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
keras/src/models/cloning.py 62.50% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #20888      +/-   ##
==========================================
- Coverage   82.24%   82.24%   -0.01%     
==========================================
  Files         561      561              
  Lines       52647    52683      +36     
  Branches     8136     8146      +10     
==========================================
+ Hits        43302    43331      +29     
- Misses       7341     7345       +4     
- Partials     2004     2007       +3     
Flag Coverage Δ
keras 82.05% <62.50%> (-0.01%) ⬇️
keras-jax 64.18% <62.50%> (-0.04%) ⬇️
keras-numpy 58.97% <0.00%> (-0.05%) ⬇️
keras-openvino 32.55% <0.00%> (+0.03%) ⬆️
keras-tensorflow 64.80% <62.50%> (-0.04%) ⬇️
keras-torch 64.24% <62.50%> (-0.04%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Assigned Reviewer
Development

Successfully merging this pull request may close these issues.

SKLearnClassifier not working properly
3 participants