GithubHelp home page GithubHelp logo

Comments (8)

nsthorat avatar nsthorat commented on July 20, 2024 1

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.

nsthorat avatar nsthorat commented on July 20, 2024

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.

nsthorat avatar nsthorat commented on July 20, 2024

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.

shiffman avatar shiffman commented on July 20, 2024

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.

nsthorat avatar nsthorat commented on July 20, 2024

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.

shiffman avatar shiffman commented on July 20, 2024

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.

shiffman avatar shiffman commented on July 20, 2024

Closing as the example is working great now! More to come...

from tensorflow-js-examples.

parweb avatar parweb commented on July 20, 2024

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