Giter Site home page Giter Site logo

ValueError: Unknown layer: 'TFOpLambda'. Please ensure you are using a `keras.utils.custom_object_scope` about keras_cv_attention_models HOT 8 OPEN

keertika-11 avatar keertika-11 commented on August 26, 2024
ValueError: Unknown layer: 'TFOpLambda'. Please ensure you are using a `keras.utils.custom_object_scope`

from keras_cv_attention_models.

Comments (8)

leondgarse avatar leondgarse commented on August 26, 2024 1

There should be a warning after from keras_cv_attention_models import *

import tensorflow as tf
from keras_cv_attention_models import *
# [WARNING] Setting TF_USE_LEGACY_KERAS=1. Make sure this is ahead of importing tensorflow or keras.

Setting export TF_USE_LEGACY_KERAS=1, or run as:

from keras_cv_attention_models import *
import tensorflow as tf
        
model = tf.keras.models.load_model('eva_giant_patch14_224_imagenet21k-ft1k.h5')

Besides, should better creating model and loading weights, instead of loading h5 directly:

from keras_cv_attention_models import eva
model = eva.EvaGiantPatch14()

from keras_cv_attention_models.

keertika-11 avatar keertika-11 commented on August 26, 2024

thank you, it worked.

from keras_cv_attention_models.

keertika-11 avatar keertika-11 commented on August 26, 2024

the model is loading now, but facing this error while retraining

TypeError: Tensors in list passed to 'values' of 'ConcatV2' Op have types [float32, float32, float16, ..float16]

logits data type and input data type have the same dtype, float32, but still getting this error

Logits Data Type: <dtype: 'float32'>
Logits Shape: (4, 1500)
Logits Data Type: <dtype: 'float32'>
Input Data Types: <dtype: 'float32'> <dtype: 'int32'>
Logits Data Type: <dtype: 'float32'>
Logits Shape: (4, 1500)
Logits Data Type: <dtype: 'float32'>
Input Data Types: <dtype: 'float32'> <dtype: 'int32'>
Logits Data Type: <dtype: 'float32'>
Logits Shape: (4, 1500)
Logits Data Type: <dtype: 'float32'>
Input Data Types: <dtype: 'float32'> <dtype: 'int32'>
Logits Data Type: <dtype: 'float32'>
Logits Shape: (4, 1500)
Logits Data Type: <dtype: 'float32'>


from keras_cv_attention_models.

leondgarse avatar leondgarse commented on August 26, 2024

Can you show a detail usage of that concat? If not sure which data causing that error, just call a cast on all data for concat.

import tensorflow as tf
xx = [tf.random.uniform([4, 100]) for _ in range(4)]
xx.append(tf.random.uniform([4, 100], dtype='float16'))

print(tf.concat([tf.cast(ii, 'float32') for ii in xx], axis=-1).shape)

from keras_cv_attention_models.

keertika-11 avatar keertika-11 commented on August 26, 2024

I am not using the concat operation anywhere in the program, I did try casting the data like this but gives the same error every time

x_batch_train = tf.cast(x_batch_train, tf.float32)
y_batch_train = tf.cast(y_batch_train, tf.float32)

from keras_cv_attention_models.

keertika-11 avatar keertika-11 commented on August 26, 2024

Here is the data loading code
the data loading part of the code

def dataset(path, batch_size, class_labels):
    def configure_for_performance(dataset, batch_size):
        dataset = dataset.repeat()
        dataset = dataset.batch(batch_size)
        dataset = dataset.prefetch(buffer_size=tf.data.experimental.AUTOTUNE)
        return dataset

    def read_filename(filename):
        image = tf.io.read_file(filename)
        image = tf.io.decode_jpeg(image, channels=3)
        image = tf.image.resize(image, [224, 224])
        return image

    def custom_tf_dataset(path, batch_size, class_labels):
        classes = os.listdir(path)
        for cls in classes:
            if cls not in class_labels:
                class_labels[cls] = len(class_labels)
        save_class_labels('class_labels.json', class_labels)

        num_classes = len(class_labels)
        print("number of classes are", num_classes)
        filenames = glob(path + '/*/*')
        num_examples = len(filenames)
        print("number of examples are", num_examples)
        random.shuffle(filenames)
        labels = [class_labels[name.split('/')[-2]] for name in filenames]
        labels = tf.data.Dataset.from_tensor_slices(labels)
        image_data = tf.data.Dataset.from_tensor_slices(filenames)
        image_data = image_data.map(read_filename)
        image_label_dataset = tf.data.Dataset.zip((image_data, labels))
        image_label_dataset = configure_for_performance(image_label_dataset, batch_size)
        return image_label_dataset, num_classes, num_examples

    return custom_tf_dataset(path, batch_size, class_labels)

class_labels = load_class_labels('class_labels.json')

train_ds, num_train_class, num_train_examples = dataset(train_dir, train_batch_size, class_labels)

from keras_cv_attention_models.

keertika-11 avatar keertika-11 commented on August 26, 2024

error

Traceback (most recent call last):
  File "/data-mount-2/eva_giant/eva_giant_train.py", line 286, in <module>
    result = distributed_train_step(dataset_inputs=batch)
  File "/home/keertika/miniconda3/envs/keras_cv/lib/python3.9/site-packages/tensorflow/python/util/traceback_utils.py", line 153, in error_handler
    raise e.with_traceback(filtered_tb) from None
  File "/tmp/__autograph_generated_file6lqoz13m.py", line 10, in tf__distributed_train_step
    per_replica_losses = ag__.converted_call(ag__.ld(strategy).run, (ag__.ld(train_step),), dict(args=(ag__.ld(dataset_inputs),)), fscope)
  File "/tmp/__autograph_generated_file3a8z_8fi.py", line 12, in tf___all_reduce_sum_fn
    retval_ = ag__.converted_call(ag__.ld(distribution).extended.batch_reduce_to, (ag__.ld(tf).distribute.ReduceOp.SUM, ag__.ld(grads_and_vars)), None, fscope)
TypeError: in user code:

    File "/data-mount-2/eva_giant/eva_giant_train.py", line 238, in distributed_train_step  *
        per_replica_losses = strategy.run(train_step, args=(dataset_inputs,))
    File "/home/keertika/miniconda3/envs/keras_cv/lib/python3.9/site-packages/tf_keras/src/optimizers/utils.py", line 173, in _all_reduce_sum_fn  *
        tf.distribute.ReduceOp.SUM, grads_and_vars

 TypeError: Tensors in list passed to 'values' of 'ConcatV2' Op have types [float32, float32, float16, float16, float16, float16, float16, float16, float16, float16, float16, float16, float16, float16, float16,................float16, float16, float16, float16, float16, float16, float16, float16, float16, float16, float16, float16, float16, float16]

from keras_cv_attention_models.

leondgarse avatar leondgarse commented on August 26, 2024
  • I'm not sure the root cause, and just done some basic tests kecam_test.ipynb, the last Training test part, but cannot reproduce this error. I think maybe it's something related with loss function? Your data loading part looks just fine.
  • Is it running on multi GPUs? How about a single GPU?

from keras_cv_attention_models.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.