0

I am working on a upgrading project from Tensorflow 1.15 to 2.4.1 ( python 3.8 ). The following is the issue I am facing. I understand the issue is with tf.contrib. How do I make this work ?

if num_epochs is not None and shuffle:
        dataset = dataset.apply(
            tf.contrib.data.shuffle_and_repeat(buffer_size=batch_size * 10, count=num_epochs)
        )
    elif shuffle:
        dataset = dataset.shuffle(buffer_size=batch_size * 10)
    elif num_epochs is not None:
        dataset = dataset.repeat(count=num_epochs)

    dataset = dataset.apply(
        tf.contrib.data.map_and_batch(map_func=parse_csv,
                                      batch_size=batch_size,
                                      num_parallel_calls=tf.data.experimental.AUTOTUNE)
    )

    I have another block below

    distribution_strategy = tf.contrib.distribute.MirroredStrategy(num_gpus=num_gpus,
                                                                   prefetch_on_device=True,
                                                                   auto_shard_dataset=True)

How do I achieve the same in Tensorflow 2.4.1

0

1 Answer 1

1

tf.contrib is no longer exist in tf2. Your converted code in tf2 is something like this:

if num_epochs is not None and shuffle:
    dataset = dataset.shuffle(batch_size * 10).repeat(num_epochs)
elif shuffle:
    dataset = dataset.shuffle(batch_size * 10)
elif num_epochs is not None:
    dataset = dataset.repeat(num_epochs)

dataset = dataset.map(parse_csv, num_parallel_calls=tf.data.AUTOTUNE).batch(batch_size)

distribution_strategy = tf.distribute.MirroredStrategy()
Sign up to request clarification or add additional context in comments.

2 Comments

in recent versions of tensorflow, AUTOTUNE is in tf.data.AUTOTUNE
@jakub Yes. I forgot to change it. Thank you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.