New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Convert Tensor to numpy array #40
Comments
To convert a tensor to numpy array, you have to run:
|
Resolved Thanks. |
Hello, |
Hi! |
Hi,
No, I'm using keras (not tensor flow directly) and I went around this
problem by using a simple code in keras that gets outputs and weights of
selected layers (and in fact that was my objective).
Franek
2017-12-27 9:52 GMT+01:00 Arundhati Banerjee <notifications@github.com>:
… Hi!
I have the same problem. @fmigas <https://github.com/fmigas> did you find
any solution?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#40 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/Afpf72KN5KzaQor0xTa2RkUUMpAkIACeks5tEgVRgaJpZM4IzP5H>
.
|
Oh ok. Thank you!
I am also using keras, and actually wanted to use the output tensor from my
model for Hamming loss evaluation (for which I intend to use sklearn
metrics - hence the need to convert to the numpy array).
Thanks,
Arundhati
…On Wed, Dec 27, 2017 at 4:06 PM, fmigas ***@***.***> wrote:
Hi,
No, I'm using keras (not tensor flow directly) and I went around this
problem by using a simple code in keras that gets outputs and weights of
selected layers (and in fact that was my objective).
Franek
2017-12-27 9:52 GMT+01:00 Arundhati Banerjee ***@***.***>:
> Hi!
> I have the same problem. @fmigas <https://github.com/fmigas> did you
find
> any solution?
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <#40#
issuecomment-354078212>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/
Afpf72KN5KzaQor0xTa2RkUUMpAkIACeks5tEgVRgaJpZM4IzP5H>
> .
>
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#40 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AOH98WFhPRw5mEOX_rkWFAk20AD1_iqfks5tEh2xgaJpZM4IzP5H>
.
|
@fmigas @b18arundhati Hi!, did you guys manage to find a solution on the conversion from the tensor to numpy array in Keras? I'm having the same problem. |
Hi!
No I did not find any direct method for the conversion. I was able to solve my problem using a workaround in Keras.
…On Sun, Jan 14, 2018 at 9:40 AM, Samuel Mensah ***@***.***> wrote:
@fmigas <https://github.com/fmigas> @b18arundhati
<https://github.com/b18arundhati> Hi!, did you guys manage to find a
solution on the conversion from the tensor to numpy array in Keras? I'm
having the same problem.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#40 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AOH98VehSX8DJC0zhX6oCNynChuy2fcmks5tKX46gaJpZM4IzP5H>
.
|
we are using Tensorflow Serving and I have written the following function to convert the PredictResponse (tensor) back to numpy array if it helps
|
for evaluating a tensor in Keras use Keras backend function "eval()" --> K.eval(my_tensor) |
Hi,@b18arundhati did you find any solution regarding this. I have the same environment in Keras. |
Try the following:
|
@b18arundhati can you please tell us what is your workaround. I am using tensor objects under keras, I want to convert them to arrays or lists so I can use them as input for another function. the output of that other function is so necessary since I am using it to calculate the loss. Any suggestions please ? |
Can you post a minimal working example, showing the tensor you want to evaluate? |
@b-fontana Thank you for your respond. In fact, my case is a bit complicated. I am defining a function that represent a custom loss. This function is using as inputs numpy arrays. So I was trying to evaluate my tensors to be numpy arrays so I can process this function but that was not possible. Because I have to fed an actual value to my tensors for that. a better explanation is in this link keras-team/keras#4075. |
I used this. but the program hangs at the eval(). what is the problem? |
@Gameatro: Try the following:
If this does not work, please paste a minimum working example so that we can reproduce your error. |
def dis(bin_image): res=distance_transform_cdt(bin_image) return res out = Conv2D(1, (1, 1), activation='sigmoid') (c9) print(out.shape) #outputs = resize_layer(scale=2)(out, method="dis") outputs=Lambda(dis)(out) (?, 256, 256, 1)ValueError Traceback (most recent call last) in base_model(IMG_WIDTH, IMG_HEIGHT, IMG_CHANNELS) /usr/local/lib/python3.6/dist-packages/keras/engine/base_layer.py in call(self, inputs, **kwargs) /usr/local/lib/python3.6/dist-packages/keras/layers/core.py in call(self, inputs, mask) in dis(bin_image) /usr/local/lib/python3.6/dist-packages/scipy/ndimage/morphology.py in distance_transform_cdt(input, metric, return_distances, return_indices, distances, indices) ValueError: setting an array element with a sequence. |
Hi Everyone, from tensorflow.keras import backend as K |
The loss function is part of the graph - I believe everything needs to be implemented using keras backend or tf functions i.e. operate on tensors not numpy arrays. |
I think there should be define |
Did you solve this? I have the same problem |
I have the same problem, but no possible to debug it. I tried to use Keras backend as suggested, but it didn't work. Here is a MWE:
|
I am trying to calculate ruc score after every epoch. For than the tensor object need to be converted to numpy array.
Following is the code I am trying.
It is giving following error:
TypeError: Expected sequence or array-like, got <class 'tensorflow.python.framework.ops.Tensor'>
Can you please tell how to convert tensor to numpy array.
I tried pred.eval() but it is showing error also.
The text was updated successfully, but these errors were encountered: