How to convert Tensor into NumPy array
Finally approach mentioned here worked for me with tensorflow-gpu==2.0.0
and keras==2.2.4
Loading a numpy array into Tensorflow input pipeline
The comment of @André put me in the right direction. The code below works.
def process_image(file_path):
label = get_label(file_path)
label = np.uint8(label)
img = np.load(file_path)
img = tf.convert_to_tensor(img/255, dtype=tf.float32)
return img , label
train_ds = images_ds.map(lambda item: tf.numpy_function(
process_image, [item], (tf.float32, tf.uint8)))
Converting KerasTensor to numpy array
There is no value to convert to numpy.
You need an input to have an output.
In keras, the best to do is to build a submodel.
submodel = Model(original_model.inputs, original_model.get_layer("encoder_output").output)
results = submodel.predict(numpy_input)
Related Topics
Pyspark - Sum a Column in Dataframe and Return Results as Int
Convert Regular Python String to Raw String
Python Pandas .Isnull() Does Not Work on Nat in Object Dtype
Return Value from Python-Shell as Response
How to Run Linux Terminal Command in Python in New Terminal
How to Remove Hashtag, @User, Link of a Tweet Using Regular Expression
Json Dump in Python Writing Newline Character and Carriage Returns in File.
Finding the Most Frequent Character in a String
Regex to Remove Commas Before a Number in Python
Adding Different Sized/Shaped Displaced Numpy Matrices
Rotate Tick Labels for Seaborn Barplot
Json.Decoder.Jsondecodeerror: Expecting Value: Line 1 Column 1 (Char 0) Python
How to Count the Number of Messages