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: 'sequential' object has no attribute "get_build_config" #949

Closed
areflesh opened this issue Sep 27, 2023 · 3 comments · Fixed by #951
Closed

attributeerror: 'sequential' object has no attribute "get_build_config" #949

areflesh opened this issue Sep 27, 2023 · 3 comments · Fixed by #951

Comments

@areflesh
Copy link

This issue appeared after switching from version 1.3.5 to 1.4.2. No code changes were done.

if args.auto_tune:
        print('AUTO TUNING ENABLED')
        def build_model(hp):
            
            model = Sequential()
            model.add(Dense(input_dims+1, input_dim=input_dims, activation='relu'))
            if args.normalize:
                model.add(tf.keras.layers.BatchNormalization())
            for i in range(hp.Int('num_layers', 1,5)):
                model.add(Dense(
                hp.Choice('units', [32, 64, 128, 256, 512, 1024]),
                activation='relu'))
                model.add(Dropout(args.dropout_rate))
            model.add(Dense(2, activation='softmax'))
            if args.gradient_clipping:
                optimizer = tf.keras.optimizers.Adam(clipnorm=args.gradient_clipping_value)
            else:
                optimizer = 'adam'
            model.compile(loss="kullback_leibler_divergence", optimizer=optimizer,
                    metrics=[
                        tf.keras.metrics.BinaryAccuracy(name='accuracy'),
                        tf.keras.metrics.Precision(name='precision'),
                        tf.keras.metrics.Recall(name='recall'),
                        tf.keras.metrics.AUC(name='auc'),
                        tf.keras.metrics.AUC(name='prc', curve='PR'),])
            return model
        if args.objective == 'prc':
            objective = keras_tuner.Objective("prc", direction="max")
        elif args.objective == 'loss':
            objective = keras_tuner.Objective("loss", direction="min")
        else:
            raise ValueError('objective must be either prc or loss')
        tuner = keras_tuner.BayesianOptimization(
            build_model,
            objective=objective,
            max_trials=args.max_trials,
            executions_per_trial=1,
            directory="s3://{}/{}/model/auto_tune".format(args.s3_bucket, args.s3_dir),
            overwrite=True)
        
        tuner.search_space_summary()
        tuner.search(dataset,
                epochs = args.max_epochs_tune,
                verbose = 2,
                class_weight = class_weights)
        print('TUNNING DONE. BEST HYPERPARAMETERS:')
        tuner.results_summary()

        model = tuner.get_best_models(num_models=1)[0]
        model.build()    

Issue appear after each trial and after third trial it says RuntimeError: Number of consecutive failures exceeded the limit of 3 and stops 
@haifeng-jin
Copy link
Collaborator

Hi @areflesh , it is probably because the TF version you use?
We do model.get_build_config() under the hood.
As I tested in colab, Sequential model class has this method.

@pacs27
Copy link

pacs27 commented Sep 28, 2023

I have the same error when I use tensorflow version 2.10 which does not have this method

Tensorflow API v2.10 Layer

@haifeng-jin
Copy link
Collaborator

It has been fixed in master. Will be available in the next release. (1.4.3)
It is much appreciated if anyone had the bug could test it on our master branch. Thanks!

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

Successfully merging a pull request may close this issue.

3 participants