You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I typed:
dynamic y = tf.Variable((3 * ((int)x)), Py.kw("name", 'y'));
also tried
dynamic y = tf.Variable(3 * ((int)x), Py.kw("name", 'y'));
same error: (An unhandled exception of type 'Microsoft.CSharp.RuntimeBinder.RuntimeBinderException' occurred in ...Additional information: Cannot convert type 'Python.Runtime.PyObject' to 'int')
I did run:
dynamic x = tf.constant(data,Py.kw("dtype","float64"), Py.kw("name", 'x'));
dynamic y = tf.Variable(tf.multiply(tf.constant(3.0, Py.kw("dtype", "float64")), x), Py.kw("name", 'y'));
dynamic model = tf.global_variables_initializer();
dynamic res = tf.Session().run(model);
Console.WriteLine(tf.Session().run(y));
But can you do the same in Python? Try skipping the dtype argument or also providing the shape argument. In this case TF may be able to resolve dtype and shape based on value.
On Fri, May 26, 2017 at 11:13 PM denfromufa ***@***.***> wrote:
But can you do the same in Python? Try skipping the dtype argument or also
providing the shape argument. In this case TF may be able to resolve dtype
and shape based on value.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#473 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AECtkPbHhN9lGqy2F1GQ_H0CpwSen7AEks5r90BkgaJpZM4Nm72a>
.
changed the title [-]An unhandled exception of type 'Microsoft.CSharp.RuntimeBinder.RuntimeBinderException' occurred in System.Core.dll[/-][+]Using Tensorflow with pythonnet[/+]on Jun 26, 2017
@mphielipp here is the full code sample, I hope you don't mind that I used it in one presentation:
// RUN THIS IN SCRIPTCS
#r C:\Python\Python35_64b\lib\site-packages\Python.Runtime.dll
usingPython.Runtime;dynamicsys;using(Py.GIL()){sys=Py.Import("sys");}dynamicnp;using(Py.GIL()){np=Py.Import("numpy");}dynamictf;using(Py.GIL()){tf=Py.Import("tensorflow");}dynamicdata=np.ones(5);dynamicx=tf.constant(data,Py.kw("name","x"));dynamicz=tf.Variable(tf.multiply(tf.pow(x,2),5),Py.kw("name","z"));dynamicy=tf.Variable(tf.multiply(tf.constant(3.0,Py.kw("dtype","float64")),x),Py.kw("name",'y'));dynamicmodel=tf.global_variables_initializer();dynamicssn=tf.Session();ssn.run(model);ssn.run(y).ToString();
@denfromufa
Because you were very active in the past, I adress you directly. Maybe you can help me. Thanks a lot in advance.
I have installed "python3.6" over anaconda3 and added "tensorflow" with the published cmd operations.
It works fine and it is possible to run the application (for instance, var tf=Py.Import("tensorflow"); ...)
But I get a failure b< one of you last statements in the above example.
2018-09-27 13:36:18.984929: I T:\src\github\tensorflow\tensorflow\core\platform\cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
@denfromufa
I am searching in the internet for an example, that uses keras over pythonnet. You wrote in an other thread a year ago, that it is possible? I have no luck by finding a syntax in c# for this. Do you have any sample code? Best regards, Daniel
Activity
den-run-ai commentedon May 25, 2017
@mphielipp i think this is the same as this issue, which is limitation of .NET DLR:
#86
You need to cast
dynamicto corresponding type (e.g.double) whendynamicis NOT 1st argument:#249 (comment)
mphielipp commentedon May 25, 2017
I try different castings (dynamic, int, double) but does not work:
dynamic y = tf.Variable( (cast)3 * x ), Py.kw("name", 'y'));
An unhandled exception of type 'Microsoft.CSharp.RuntimeBinder.RuntimeBinderException' occurred in PythonNet2.exe
Additional information: Operator '*' cannot be applied to operands of type 'int' and 'Python.Runtime.PyObject'
den-run-ai commentedon May 25, 2017
Here is how casting works:
dynamic y = tf.Variable( 3 * ((int)x) ), Py.kw("name", 'y'));I put extra brackets to disambiguate the operation ordering.
mphielipp commentedon May 25, 2017
I typed:
dynamic y = tf.Variable((3 * ((int)x)), Py.kw("name", 'y'));
also tried
dynamic y = tf.Variable(3 * ((int)x), Py.kw("name", 'y'));
same error: (An unhandled exception of type 'Microsoft.CSharp.RuntimeBinder.RuntimeBinderException' occurred in ...Additional information: Cannot convert type 'Python.Runtime.PyObject' to 'int')
mphielipp commentedon May 25, 2017
wait x is not an int, x was declare in the previous line:
dynamic x = tf.constant(data, Py.kw("name", 'x'));
den-run-ai commentedon May 25, 2017
den-run-ai commentedon May 26, 2017
I don't have much experience with tensorflow. Can you point to any tutorial that does the same in Python API?
Can't you build your expressions only using tensorflow math functions, not Python operators?
https://www.tensorflow.org/api_guides/python/math_ops
mphielipp commentedon May 26, 2017
Yes. This is a sample code:
import tensorflow as tf
import numpy as np
data = np.random.randint(1000, size=10000)
print (data)
x = tf.constant(data, name='x')
y = tf.Variable((x * x) * 5-3*x+15, name='y')
model = tf.global_variables_initializer()
with tf.Session() as session:
session.run(model)
print(session.run(y))
mphielipp commentedon May 26, 2017
it seems that the operators are pass as Python ones in this example.
den-run-ai commentedon May 26, 2017
looks like possible using only tensorflow math:
mphielipp commentedon May 26, 2017
ok. thanks!!!
mphielipp commentedon May 26, 2017
TypeError : Input 'y' of 'Mul' Op has type float64 that does not match type int32 of argument 'x'."}
x is type ndarray and each element if float 64
den-run-ai commentedon May 26, 2017
well i guess you need to specify the types:
mphielipp commentedon May 26, 2017
Yes!! Thanks!!
mphielipp commentedon May 26, 2017
I tried the specification but did not change the 3 to 3.0. Thanks again!
mphielipp commentedon May 26, 2017
I did run:
dynamic x = tf.constant(data,Py.kw("dtype","float64"), Py.kw("name", 'x'));
dynamic y = tf.Variable(tf.multiply(tf.constant(3.0, Py.kw("dtype", "float64")), x), Py.kw("name", 'y'));
dynamic model = tf.global_variables_initializer();
dynamic res = tf.Session().run(model);
Console.WriteLine(tf.Session().run(y));
But it does not initialize properly:
{"FailedPreconditionError : Attempting to use uninitialized value y\n\t [[Node: _send_y_0 = _SendT=DT_DOUBLE, client_terminated=true, recv_device="/job:localhost/replica:0/task:0/cpu:0", send_device="/job:localhost/replica:0/task:0/cpu:0", send_device_incarnation=3877403296068384333, tensor_name="y:0", _device="/job:localhost/replica:0/task:0/cpu:0"]]"}
den-run-ai commentedon May 26, 2017
mphielipp commentedon May 26, 2017
Great!! Thanks!!
mphielipp commentedon May 26, 2017
{"TypeError : float() argument must be a string or a number, not '0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]'"}
den-run-ai commentedon May 26, 2017
But can you do the same in Python? Try skipping the dtype argument or also providing the shape argument. In this case TF may be able to resolve dtype and shape based on value.
mphielipp commentedon May 28, 2017
[-]An unhandled exception of type 'Microsoft.CSharp.RuntimeBinder.RuntimeBinderException' occurred in System.Core.dll[/-][+]Using Tensorflow with pythonnet[/+]den-run-ai commentedon Sep 14, 2017
@mphielipp here is the full code sample, I hope you don't mind that I used it in one presentation:
danieljaro commentedon Sep 27, 2018
@denfromufa
Because you were very active in the past, I adress you directly. Maybe you can help me. Thanks a lot in advance.
I have installed "python3.6" over anaconda3 and added "tensorflow" with the published cmd operations.
It works fine and it is possible to run the application (for instance, var tf=Py.Import("tensorflow"); ...)
But I get a failure b< one of you last statements in the above example.
2018-09-27 13:36:18.984929: I T:\src\github\tensorflow\tensorflow\core\platform\cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
Do you have any idea?
den-run-ai commentedon Sep 27, 2018
That is a warning, not an error
danieljaro commentedon Sep 27, 2018
ok! thank's for the answer.
danieljaro commentedon Sep 28, 2018
@denfromufa
I am searching in the internet for an example, that uses keras over pythonnet. You wrote in an other thread a year ago, that it is possible? I have no luck by finding a syntax in c# for this. Do you have any sample code? Best regards, Daniel