RuntimeError: as_numpy_iterator() is not supported while tracing functions

2024/9/20 8:57:09

while i was using function as_numpy_iterator() got error

--------------------------------------------------------------------------- RuntimeError Traceback (most recent calllast) in ()----> 1 image = get_image_data(image_paths)

1 frames/tensorflow-2.1.0/python3.6/tensorflow_core/python/data/ops/dataset_ops.pyin as_numpy_iterator(self)488 """489 if not context.executing_eagerly():--> 490 raise RuntimeError("as_numpy_iterator() is not supported while tracing "491 "functions")492 for component_spec in nest.flatten(self.element_spec):

RuntimeError: as_numpy_iterator() is not supported while tracingfunctions

my code is

    # creating a function called get_dataset, which creates a dataset of image data from file paths.
def get_dataset(image_paths):filename_tensor = tf.constant(image_paths)dataset = tf.data.Dataset.from_tensor_slices(filename_tensor)def _map_fn(filename):return decode_image(filename=filename)return dataset.map(_map_fn)
#
def get_image_data(image_paths):dataset = get_dataset(image_paths)return list(dataset.as_numpy_iterator())
image = get_image_data(image_paths)

it throws error in using dataset.as_numpy_iterator() . I had used image paths of two array of filename

Answer

The error message here is a bit confusing, since it talks about tracing functions, but I ran into this and realized it's a Dataset feature that's only supported when eager execution is enabled. It's enabled by default in TensorFlow 2.x, but but you can also manually enable it in later 1.x versions. If you enable it, this error message should disappear.

https://en.xdnf.cn/q/72441.html

Related Q&A

Pandas assert_frame_equal error

Im building test cases and I want to compare 2 dataframes. Even though dataframe have the same columns and values assert_frame_equal reports are not equal. Column order is different, I tried reordering…

Multiple lines on line plot/time series with matplotlib

How do I plot multiple traces represented by a categorical variable on matplotlib or plot.ly on Python? I am trying to replicate the geom_line(aes(x=Date,y=Value,color=Group) function from R.Is there …

Python ABCs: registering vs. subclassing

(I am using python 2.7) The python documentation indicates that you can pass a mapping to the dict builtin and it will copy that mapping into the new dict:http://docs.python.org/library/stdtypes.html#…

python - ensure script is activated only once

Im writing a Python 2.7 script. In summary, this script is being run every night on Linux and activates several processes.Id like to ensure this script is not run multiple times in parallel (basically …

How to set up auto-deploy to AppEngine when pushing to Git Repository

Ive heard that other platforms support auto-deployment of their code to production when they push changes to their Git repository.Can I set up something similar to this for AppEngine? How?Im using Py…

#include zbar.h 1 error generated when running pip install zbar

Im trying to run pip install zbar and for some reason I cant seem to find an answer to solve this dependency issue. Any help would be extremely appreciated. See traceback below:Downloading/unpacking zb…

Django model field default based on another model field

I use Django Admin to build a management site. There are two tables, one is ModelA with data in it, another is ModelB with nothing in it. If one model field b_b in ModelB is None, it can be displayed o…

How do I improve remove duplicate algorithm?

My interview question was that I need to return the length of an array that removed duplicates but we can leave at most 2 duplicates. For example, [1, 1, 1, 2, 2, 3] the new array would be [1, 1, 2, 2,…

Looking for values in nested tuple

Say I have:t = ((dog, Dog),(cat, Cat),(fish, Fish), )And I need to check if a value is in the first bit of the nested tuple (ie. the lowercase bits). How can I do this? The capitalised values do not m…

Multiple lines user input in command-line Python application

Is there any easy way to handle multiple lines user input in command-line Python application?I was looking for an answer without any result, because I dont want to:read data from a file (I know, its t…