Comments (10)
I'm planning to redefine PyObjectWrapper#method
method to return a wrapper object of Python's function object so that we can write tf.keras.layers.Dense(512, activation=tf.nn.method(:relu))
.
On ruby-core, people are discussing a syntax sugar for method reference, which is maybe introduced in the future Ruby. I think it's very good that this syntax sugar can be used for this case.
from pycall.rb.
This is an awesome project. Please continue to innovate here as I think it opens a world of opportunity to Ruby developers.
from pycall.rb.
@mightystrong I've implemented easy ways to obtain functional attributes in this pull-request #72
After merging it, you can write it like tf.keras.layers.Dense(512, activation: tf.nn[:relu])
because tf.nn
is a module.
And if you want to get functional attributes from non-module objects, you can use PyCall.getattr
method.
Do these resolve your issue?
from pycall.rb.
@sp00ck there is a dedicated project for that:
https://github.com/somaticio/tensorflow.rb
from pycall.rb.
@sp00ck I heared that some people tried to use Python's tensorflow via pycall.rb, and they've succeeded. As tensorflow is very changed day by day, it is unclear that Python's tensorflow can work on pycall.rb now. Please check it by yourself. And if you encounter any troubles, please report it as an issue.
As @arbox mentioned, you can use tensorflow.rb, too. It is just a binding of Tensorflow's C API. But you cannot use such features in tf.contrib.*
, which are provided only in Python API, with tensorflow.rb. If you want to use them from Ruby, you need to use pycall.rb.
from pycall.rb.
I've been using tensorflow via PyCall but it has some issues. For example, if you simply try running the example on the tensorflow tutorials page (below) you first run into a lot of conversion challenges dealing with tuples. You also need to convert other lines such as tf.keras.layers.Dense(512, activation=tf.nn.relu)
to tf.keras.layers.Dense(512, activation: tf.nn.relu)
.
While setting the model variable, PyCall throws an error saying <type 'exceptions.TypeError'>: relu() takes at least 1 argument (0 given)
. Running this code directly in Python, doesn't require the argument to be given, so it seems there is some work to do here. Maybe there's an answer of which I'm not aware.
import tensorflow as tf
mnist = tf.keras.datasets.mnist
(x_train, y_train),(x_test, y_test) = mnist.load_data()
x_train, x_test = x_train / 255.0, x_test / 255.0
model = tf.keras.models.Sequential([
tf.keras.layers.Flatten(),
tf.keras.layers.Dense(512, activation=tf.nn.relu),
tf.keras.layers.Dropout(0.2),
tf.keras.layers.Dense(10, activation=tf.nn.softmax)
])
model.compile(optimizer='adam',
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])
model.fit(x_train, y_train, epochs=5)
model.evaluate(x_test, y_test)
from pycall.rb.
@mightystrong Thank you for using PyCall, and reporting back your feeling of use.
This issue comes from the difference that Ruby is lisp-2 but Python is lisp-1.
Now you can get function object by using getattr
method defined in LibPython::Helpers module, but I understand this is too much uncomfortable.
I’ve decided to introduce other easy way to get function attributes.
from pycall.rb.
There is another idea I got from @znz, that is letting obj.name!
returns a function reference.
It is possible because Pytohn doesn't permit !
in a method name.
But, I currently don't prefer this idea...
from pycall.rb.
@mrkn How would you call tf.keras.layers.Dense(512, activation: tf.nn.relu)
instead in the current version of PyCall so that it doesn't throw the argument required error?
Now you can get function object by using getattr method defined in LibPython::Helpers module, but I understand this is too much uncomfortable.
from pycall.rb.
from pycall.rb.
Related Issues (20)
- Can't iterate `PrettyDict` of Pandas
- How to use PyCall.exec/eval ? HOT 2
- CI: Add windows-latest in conda job
- gem install --pre pycall *Error* on Windows Ruby installed by Rubyinstaller HOT 7
- "[BUG] object allocation during garbage collection phase" on Windows HOT 1
- uninitialized constant PyCall::LibPython::Helpers HOT 7
- Using pycall on Dokku (Heroku compatible alternative) HOT 13
- PyCall::LibPythonFunctionNotFound (Unable to find the required symbol in libpython: _Py_NoneStruct) HOT 5
- _Py_NoneStruct (PyCall::LibPythonFunctionNotFound) HOT 1
- how to deploy to heroku? HOT 9
- import_module from other folder than lib? HOT 1
- Question about loading a subclass HOT 1
- exceptions not raised from within without_gvl block HOT 1
- pycall freezes and never resolves during a controller function HOT 1
- DeprecationWarning: The distutils.sysconfig module is deprecated, use sysconfig instead
- Catching python STDOUT
- Memory issue HOT 2
- Memory leak with numpy HOT 1
- Unable to find required symbol in libpython when using a conda env HOT 1
- call with docx module, GIL is released (the current Python thread state is NULL) HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pycall.rb.