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 commented on May 25, 2017
@mphielipp i think this is the same as this issue, which is limitation of .NET DLR:
#86
You need to cast dynamic to corresponding type (e.g. double) when dynamic is NOT 1st argument:
#249 (comment)
mphielipp commented on 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 commented on 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 commented on 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 commented on 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 commented on May 25, 2017
den-run-ai commented on 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 commented on 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 commented on May 26, 2017
it seems that the operators are pass as Python ones in this example.
den-run-ai commented on May 26, 2017
looks like possible using only tensorflow math:
activate py35 (py35) C:\Users\denis.akhiyarov>conda update python (py35) C:\Users\denis.akhiyarov>pip install tensorflow (py35) C:\Users\denis.akhiyarov>python Python 3.5.3 |Continuum Analytics, Inc.| (default, May 15 2017, 10:43:23) [MSC v .1900 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import tensorflow >>> import tensorflow as tf >>> import numpy as np >>> data = np.ones(5) >>> x=tf.constant(data, name='x') >>> y = tf.Variable((x * x) * 5 - 3 * x + 15, name='y') >>> z = tf.Variable(tf.multiply(tf.pow(x,2),5), name='z') >>> exit() (py35) C:\Users\denis.akhiyarov>pip install pythonnet -U (py35) C:\Users\denis.akhiyarov>set PYTHONHOME=C:\Python\Python27_64b\envs\py35 (py35) C:\Users\denis.akhiyarov>scriptcs scriptcs (ctrl-c to exit or :help for help) > #r C:\Python\Python27_64b\envs\py35\lib\site-packages\Python.Runtime.dll > using Python.Runtime; > dynamic sys; > using (Py.GIL()) {sys=Py.Import("sys");} > dynamic np; > using (Py.GIL()) {np=Py.Import("numpy");} > dynamic tf; > using (Py.GIL()) {tf=Py.Import("tensorflow");} > dynamic data = np.ones(5); > dynamic x=tf.constant(data, Py.kw("name","x")); > dynamic z = tf.Variable(tf.multiply(tf.pow(x,2),5), Py.kw("name","z"));mphielipp commented on May 26, 2017
ok. thanks!!!
mphielipp commented on May 26, 2017
dynamic data = np.ones(5.0); dynamic x = tf.constant(data, Py.kw("name", 'x')); dynamic y = tf.Variable(tf.multiply(tf.constant(3) ,x), Py.kw("name", 'y'));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 commented on May 26, 2017
well i guess you need to specify the types:
dynamic y = tf.Variable(tf.multiply(tf.constant(3.0,Py.kw("dtype","float64")),x), Py.kw("name", 'y'));mphielipp commented on May 26, 2017
Yes!! Thanks!!
mphielipp commented on May 26, 2017
I tried the specification but did not change the 3 to 3.0. Thanks again!
mphielipp commented on 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 commented on May 26, 2017
mphielipp commented on May 26, 2017
Great!! Thanks!!
mphielipp commented on May 26, 2017
// w = tf.Variable([1.0, 2.0], name = "w") dynamic wa = np.array(new List<double> { 1.0, 2.0}); dynamic w = tf.Variable(wa, Py.kw("dtype", "float64"), Py.kw("name", 'w'));{"TypeError : float() argument must be a string or a number, not '0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]'"}
den-run-ai commented on 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 commented on May 28, 2017
den-run-ai commented on Sep 14, 2017
@mphielipp here is the full code sample, I hope you don't mind that I used it in one presentation:
danieljaro commented on 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 commented on Sep 27, 2018
That is a warning, not an error
danieljaro commented on Sep 27, 2018
ok! thank's for the answer.
danieljaro commented on 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