Giter VIP home page Giter VIP logo

Comments (10)

mrkn avatar mrkn commented on June 3, 2024 1

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.

mightystrong avatar mightystrong commented on June 3, 2024 1

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.

mrkn avatar mrkn commented on June 3, 2024 1

@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.

arbox avatar arbox commented on June 3, 2024

@sp00ck there is a dedicated project for that:
https://github.com/somaticio/tensorflow.rb

from pycall.rb.

mrkn avatar mrkn commented on June 3, 2024

@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.

mightystrong avatar mightystrong commented on June 3, 2024

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.

mrkn avatar mrkn commented on June 3, 2024

@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.

mrkn avatar mrkn commented on June 3, 2024

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.

mightystrong avatar mightystrong commented on June 3, 2024

@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.

mightystrong avatar mightystrong commented on June 3, 2024

from pycall.rb.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.