-
Notifications
You must be signed in to change notification settings - Fork 502
Minimal Lambda layer implementation #115
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
I welcome anyone who wants to write tests and verify this implementation. I wrote the original in a version that was precompiled by babel, and did not have the opportunity to verify this version. |
Hi linusmartensson, Because keras.js don't support instance normalization layer(contrast normalization), after saw your pull requests, I tried using Lambda layer to achieve instance norm function. My Lambda layer codes are:
Then I did following steps:
In your commit, it says"This layer requires you to re-implement lambda nodes in javascript", I'm sorry I didn't understand it. Could you please tell me what's the meaning of this words or which step I miss? Great thanks! |
Hello Ming,
The meaning in my commit was that your contrast_norm-function will have to
be recreated in javascript, since it is not possible for javascript to
deserialize and run the python code in your Lambda node. You will still
have to reimplement the lambda using tensors and/or webgl as necessary to
achieve your intended result.
Best Regards,
Linus
ons 14 mars 2018 kl 08:12 skrev ming <notifications@github.com>:
… Hi linusmartensson,
Because keras.js don't support instance normalization layer(contrast
normalization), after saw your pull requests, I tried using Lambda layer to
achieve instance norm function. My Lambda layer codes are:
def contrast_norm(x): epsilon=1e-3 dims = list(range(1,K.ndim(x)-1))
x_mean = K.mean(x, dims, keepdims=True) x_stddev = K.std(x, dims,
keepdims=True) + epsilon x = (x - x_mean) / x_stddev return x def
instancenorm(): return Lambda(contrast_norm)
Then I did following steps:
1. I replaced batchnorm layer of my keras model with this Lambda
layer, then trained and converted model as usual.
2. I used demos of keras.js, just replaced demos' model files with my
model's. (My model run successfully before when using batchnorm layer)
3. I cloned your codes and call 'npm run build' to build codes, then
call 'npm run demos:watch'. There was no error appeared.
When I open demos in browser, it says"Note: this browser does not support
WebGL 2 or the features necessary to run in GPU mode', and the browser stop
responding. (This problem didn't happen before)
In your commit, it says"This layer requires you to re-implement lambda
nodes in javascript", I'm sorry I didn't understand it. Could you please
tell me what's the meaning of this words or which step I miss?
Great thanks!
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#115 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAbmSZqWkJ_vkDz7vGVERZ35O61VTH3sks5teMLMgaJpZM4SkuOk>
.
|
Hi Linus, Thanks for your explanation! It made me more clear. After days of source codes reading, reimplementing the lambda using tensors or webgl is still complicated to me. But I tried to implement contrast norm layer by adding some codes on batch norm layer. Many Thanks to your help! |
I had a finished model and needed it to fit into keras-js. Seeing as I had some lambda layers in that model, it seemed like the easiest solution was to implement this in keras-js and push it back to master.
The implementation is more or less low-effort, but works perfectly fine for my scenario. There may be a cleaner method to push through the lambda functions, but I can't claim enough experience with keras-js to determine how that should be done.