Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

'_UserObject' object has no attribute 'summary' #196

Open
aynesss opened this issue Feb 16, 2022 · 4 comments
Open

'_UserObject' object has no attribute 'summary' #196

aynesss opened this issue Feb 16, 2022 · 4 comments

Comments

@aynesss
Copy link

aynesss commented Feb 16, 2022

Hello, I'm trying to load a r50_1x_sk0/saved_model of pretrained checkpoint-tf2 of simCLRv2, to just fine tuned but I'm coming across this error:
'_UserObject' object has no attribute 'summary'
I would to apply .summary() .fit() and .predict()
Here is a part of my code

def create_model(path):
    baseModel = tf.saved_model.load(path)
    baseModel.summary()   
    model_output = tf.keras.layers.Dense(3, name="head_supervised_new")(baseModel)
  
    model = tf.keras.Model(inputs=baseModel, outputs=model_output)
    model.compile(optimizer=tf.keras.optimizers.SGD(learning_rate=0.001),
              loss=tf.keras.losses.CategoricalCrossentropy(),
              metrics=[tf.keras.metrics.CategoricalAccuracy()])  
    return model
loaded_model = create_model("gs://simclr-checkpoints-tf2/simclrv2/pretrained/r50_2x_sk1/saved_model")
loaded_model.fit(training_set)
@yangruo1226
Copy link

Hello, I'm trying to load a r50_1x_sk0/saved_model of pretrained checkpoint-tf2 of simCLRv2, to just fine tuned but I'm coming across this error: '_UserObject' object has no attribute 'summary' I would to apply .summary() .fit() and .predict() Here is a part of my code

def create_model(path):
    baseModel = tf.saved_model.load(path)
    baseModel.summary()   
    model_output = tf.keras.layers.Dense(3, name="head_supervised_new")(baseModel)
  
    model = tf.keras.Model(inputs=baseModel, outputs=model_output)
    model.compile(optimizer=tf.keras.optimizers.SGD(learning_rate=0.001),
              loss=tf.keras.losses.CategoricalCrossentropy(),
              metrics=[tf.keras.metrics.CategoricalAccuracy()])  
    return model
loaded_model = create_model("gs://simclr-checkpoints-tf2/simclrv2/pretrained/r50_2x_sk1/saved_model")
loaded_model.fit(training_set)

I have the same issue.

@ilia10000
Copy link

I was having the same problem but it turns out loaded_model is a User_Object, the actual model is located at loaded_model.model.
So for example try loaded_model.model.summary()

@hahahannes
Copy link

I was having the same problem but it turns out loaded_model is a User_Object, the actual model is located at loaded_model.model. So for example try loaded_model.model.summary()

I think this only works with

import tensorflow as tf
model = tf.keras.models.load_model()
model.model.summary()

If you use

model = tf.saved_model.load()

you will get a UserObject again after accessing model.model

@hahahannes
Copy link

Did anyone get the model to work with keras methods?
I trying to access the layers e.g. the projection_head but get AttributeError: Layer projection_head has no inbound nodes.

after:

import tensorflow as tf
saved_model_path = 'gs://simclr-checkpoints-tf2/simclrv2/pretrained/r50_1x_sk0/saved_model/'
model = tf.keras.models.load_model(saved_model_path).model
model.get_layer('projection_head')

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

No branches or pull requests

4 participants