Comments (8)
Yeah actually we should probably do this in the library, I'll send a fix but for now just slice it (slice is shallow so is cheap) :)
from tensorflow-js-examples.
Hey Dan!
What kind of strange behavior are you seeing?
One thing I would note is you shouldn't override the value like this: https://github.com/shiffman/Tensorflow-JS-Examples/blob/master/04_neuro_evolution/nn.js#L55
Actually because of the way we're sharing these TypedArrays you're in place mutating the underlying values in the Tensor :/. One simple solution is to use arraySync instead of dataSync since we do a copy. Or you can copy the output of dataSync to a new Float32Array (using a new Float32Array and TypedArray.set).
from tensorflow-js-examples.
BTW, if you use the arraySync route you have to deal with the dimensionality of weights, maybe use the second approach of copying the Float32Array output of the dataSync.
from tensorflow-js-examples.
Aha, this is the issue! (Big thanks to @meiamsome who also discovered this.) I didn't realize that dataSync()
doesn't copy the data! So I was shallow instead of deep copying and the new population was sharing weights across models! An extra slice()
function to copy sorts out the issue.
let arr = w[i].dataSync().slice();
More soon!
from tensorflow-js-examples.
FYI, we decided not to do this in the library. TypedArray.slice() is shallow but in JS that's not a lazy copy, it will copy all the numbers to the new array slowing down dataSync(). I'm going to clarify this in documentation, but unfortunately we're not going to make the change upstream so you'll have to slice the TypedArray in your code.
from tensorflow-js-examples.
No worries, I appreciate all the info and help! Having this handled by tf.js is by no means necessary for what I'm working on.
from tensorflow-js-examples.
Closing as the example is working great now! More to come...
from tensorflow-js-examples.
Well thank you, I find this conversation after torturing my natural neural brain for the entire afternoon.
exactly what need !
By the way the repository location code of @shiffman change
https://github.com/shiffman/Tensorflow-JS-Examples/blob/master/04_neuro_evolution_flappy/nn.js
from tensorflow-js-examples.
Related Issues (8)
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 tensorflow-js-examples.