Closed emlys closed 3 years ago
@emlys This behaviour seems fine. The list architecture you passing contains initialized layers outside of the function.
Here is an example:
In [42]: architecture = [keras.layers.Dense(128, input_dim=55, activation='sigmoid')]
In [43]: def f(arc=None):
...: print(arc)
In [44]: f(architecture)
[<tensorflow.python.keras.layers.core.Dense object at 0x7fe9f2144b50>]
In [45]: f(architecture)
[<tensorflow.python.keras.layers.core.Dense object at 0x7fe9f2144b50>] # same object as above
In [46]: f([keras.layers.Dense(128, input_dim=55, activation='sigmoid')])
[<tensorflow.python.keras.layers.core.Dense object at 0x7fe9f2127850>]
In [47]: f([keras.layers.Dense(128, input_dim=55, activation='sigmoid')])
[<tensorflow.python.keras.layers.core.Dense object at 0x7fe9f2446810>] # different since it gets initialized when the print function is called.
@emlys Moving this issue to closed status as there has been no activity, in case you still face the error please create a new issue.
System information
Describe the current behavior
I am doing k-fold cross validation of my model. To do this I need to start each fold with a new, un-trained model object that has not carried over any information from the past fold. I want to reuse the code on multiple different architectures, so I am passing a list of keras layers into a
create_model
method, which instantiates akeras.Sequential
model and compiles it.Despite apparently creating a new model at a new address upon each call of
create_model
, information is being carried over from one fold to the next. The accuracy at the start of one fold is about where it was at the end of the last fold. If I instantiate the layers within thecreate_model
method, the accuracy restarts at the beginning of each fold.Describe the expected behavior
Different instances of a model object should not share information. It's confusing, and it would be nice to be able to pass in a list of layers to a
create_model
method.Code to reproduce the issue
Other info / logs
Example of output when run on my dataset: