-
Notifications
You must be signed in to change notification settings - Fork 12
[WIP] Add part of the Keras API #5
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
base: master
Are you sure you want to change the base?
Conversation
activity_regularizer: py.NoneOr[String] = py.None, | ||
kernel_constraint: py.NoneOr[String] = py.None, | ||
bias_constraint: py.NoneOr[String] = py.None, | ||
input_shape: py.NoneOr[(Int, Int, Int)] = py.None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
input_shape
should be provided via **kwargs
(https://www.tensorflow.org/api_docs/python/tf/keras/layers/Conv2D) but I didn't know how to do it with scalapy
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, this is something I need to work on supporting, probably with an annotation. In the meantime, you should be able to handle this by calling this.as[py.Dynamic].Conv2D(..., input_shape=input_shape, ...)
since the dynamic API does support kwargs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried the following in dynamic API:
val models2 = py.module("tensorflow").keras.models
val layers2 = py.module("tensorflow").keras.layers
val model = models2.Sequential() // kerasA.models.as[py.Dynamic].Sequential() // kerasA.models.Sequential()
model.add(layers2.Conv2D(filters = 32, kernel_size = (3, 3), activation = "relu", input_shape = (28, 28, 1)))
And it fails with:
[error] Exception in thread "main" me.shadaj.scalapy.py.PythonException: <class 'TypeError'> Dimension value must be integer or None or have an __index__ method, got 32.0
[error] at me.shadaj.scalapy.py.CPythonInterpreter$.$anonfun$throwErrorIfOccured$1(CPythonInterpreter.scala:110)
[error] at me.shadaj.scalapy.py.Platform$.Zone(Platform.scala:10)
[error] at me.shadaj.scalapy.py.CPythonInterpreter$.throwErrorIfOccured(CPythonInterpreter.scala:96)
[error] at me.shadaj.scalapy.py.CPythonInterpreter$.$anonfun$load$1(CPythonInterpreter.scala:119)
[error] at me.shadaj.scalapy.py.Platform$.Zone(Platform.scala:10)
[error] at me.shadaj.scalapy.py.CPythonInterpreter$.load(CPythonInterpreter.scala:116)
[error] at me.shadaj.scalapy.py.package$.eval(package.scala:84)
[error] at me.shadaj.scalapy.py.AnyDynamics.applyDynamicNamed(Dynamic.scala:17)
[error] at me.shadaj.scalapy.py.AnyDynamics.applyDynamicNamed$(Dynamic.scala:14)
[error] at me.shadaj.scalapy.py.package$$anon$11$$anon$12.applyDynamicNamed(package.scala:84)
[error] at me.shadaj.scalapy.py.AnyDynamics.applyDynamic(Dynamic.scala:11)
[error] at me.shadaj.scalapy.py.AnyDynamics.applyDynamic$(Dynamic.scala:8)
[error] at me.shadaj.scalapy.py.package$$anon$11$$anon$12.applyDynamic(package.scala:84)
[error] at me.shadaj.scalapy.tensorflow.MnistExample$.delayedEndpoint$me$shadaj$scalapy$tensorflow$MnistExample$1(MnistExample.scala:56)
[error] at me.shadaj.scalapy.tensorflow.MnistExample$delayedInit$body.apply(MnistExample.scala:10)
[error] at scala.Function0.apply$mcV$sp(Function0.scala:39)
[error] at scala.Function0.apply$mcV$sp$(Function0.scala:39)
[error] at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:17)
[error] at scala.App.$anonfun$main$1$adapted(App.scala:80)
[error] at scala.collection.immutable.List.foreach(List.scala:392)
[error] at scala.App.main(App.scala:80)
[error] at scala.App.main$(App.scala:78)
[error] at me.shadaj.scalapy.tensorflow.MnistExample$.main(MnistExample.scala:10)
[error] at me.shadaj.scalapy.tensorflow.MnistExample.main(MnistExample.scala)
It casts 32
to Double
somewhere. I didn't have this issue in previous versions (with JEP) so perhaps there is a bug on master?
@shadaj
Hi, I added small part of Keras API - enough to solve MNIST example.
It is not working yet and I have lots of questions though :D
I skipped a lot of functionality but I hope it could be a good starting point.
When I run MnistExample it fails at runtime with:
I think it happens when creating second
Conv2D
layer.I used local version of scalapy-numpy with these changes: shadaj/scalapy-numpy@master...Avasil:shape-reshape (needed
shape
and reshape` for the example)Advice/help would be appreciated!