Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WARNING:tensorflow:AutoGraph could not transform <function format_example at ...> and will run it as-is

My question is related to this and this one here. I am using PyCharm on Windows and Python 3.7.8 and Tensorflow 2.2.0:

print (sys.version)
3.7.8 (tags/v3.7.8:4b47a5b6ba, Jun 28 2020, 08:53:46) [MSC v.1916 64 bit (AMD64)]

print(tf.__version__)
2.2.0

When I run this code from this colab tutorial:

import os

import numpy as np

import matplotlib.pyplot as plt
import tensorflow as tf
import tensorflow_datasets as tfds

(raw_train, raw_validation, raw_test), metadata = tfds.load(
    'cats_vs_dogs',
    split=['train[:80%]', 'train[80%:90%]', 'train[90%:]'],
    with_info=True,
    as_supervised=True,
)
IMG_SIZE = 160 # All images will be resized to 160x160

def format_example(image, label):
  image = tf.cast(image, tf.float32)
  image = (image/127.5) - 1
  image = tf.image.resize(image, (IMG_SIZE, IMG_SIZE))
  return image, label

and then try to run this line:

train = raw_train.map(format_example)

I get the WARNING:

WARNING:tensorflow:AutoGraph could not transform <function format_example at 0x00000265A2DB4E58> and will run it as-is.
Please report this to the TensorFlow team. When filing the bug, set the verbosity to 10 (on Linux, `export AUTOGRAPH_VERBOSITY=10`) and attach the full output.
Cause: Unable to locate the source code of <function format_example at 0x00000265A2DB4E58>. Note that functions defined in certain environments, like the interactive Python shell do not expose their source code. If that is the case, you should to define them in a .py source file. If you are certain the code is graph-compatible, wrap the call using @tf.autograph.do_not_convert. Original error: could not get source code
To silence this warning, decorate the function with @tf.autograph.experimental.do_not_convert

I only get this WARNING when using PyCharm on my local pc. When I run it in colab no problems. What is the issue here and is this relevant or can I ignore the WARNING?

like image 986
Stat Tistician Avatar asked Jul 16 '20 09:07

Stat Tistician


People also ask

Can TensorFlow Auto Graph transform?

WARNING:tensorflow:AutoGraph could not transform and will run it as-is. Please report this to the TensorFlow team. When filing the bug, set the verbosity to 10 (on Linux, `export AUTOGRAPH_VERBOSITY=10`) and attach the full output.

How do I report a bug in TensorFlow?

Please report this to the TensorFlow team. When filing the bug, set the verbosity to 10 (on Linux, `export AUTOGRAPH_VERBOSITY=10`) and attach the full output. Cause: Unable to locate the source code of <function format_example at 0x00000265A2DB4E58>.

What is the difference between TensorFlow min and TF transform?

For example, tft.min computes the minimum of a tensor over the dataset. tf.Transform provides a fixed set of analyzers, but this will be extended in future versions. By combining analyzers and regular TensorFlow functions, users can create flexible pipelines for transforming data.

How do you transform data in TensorFlow?

By combining analyzers and regular TensorFlow functions, users can create flexible pipelines for transforming data. The following preprocessing function transforms each of the three features in different ways, and combines two of the features: Here, x, y and s are Tensor s that represent input features.


1 Answers

Like OP I get this warning in JupyterLab but not in Colab. But this only happens if I use a lambda.

train = raw_train.map(lambda x: x)

If I use a named function like the OP is doing here the warning goes away.

train = raw_train.map(format_example)

DataSet.map() always builds a graph even if you are in the eager mode. I think the graph builder is running into some kind of confusion.

like image 151
RajV Avatar answered Oct 06 '22 18:10

RajV