tensorflow / tfjs

A WebGL accelerated JavaScript library for training and deploying ML models.
https://js.tensorflow.org
Apache License 2.0
18.37k stars 1.92k forks source link

Can i make a Transfer learning in nodejs #925

Closed joel1725 closed 5 years ago

joel1725 commented 5 years ago

To get help from the community, check out our Google group.

TensorFlow.js version

"@tensorflow-models/mobilenet": "^0.2.2", "@tensorflow/tfjs": "^0.13.5", "@tensorflow/tfjs-node": "^0.1.9",

Browser version

i'm not using any broser just windows CMD.

Describe the problem or feature request

I'm trying to make a transfer learning with tensorflow js and node js, and when i trie to do this it show me: UnhandledPromiseRejectionWarning: TypeError: mobilenet.getLayer is not a function

Code to reproduce the bug / link to feature request

const tf = require('@tensorflow/tfjs') const mn = require('@tensorflow-models/mobilenet'); require('@tensorflow/tfjs-node')

const MOBILNET_PATH = 'model/model.json'; let mobilenet;

mobilenet = new mn.MobileNet(1, 1); mobilenet.path = file://${MOBILNET_PATH} await mobilenet.load();

// Gets a rid of the dense layers of the model const layer = mobilenet.getLayer('conv_pw_13_relu');

adwellj commented 5 years ago

I recently did this, but unfortunately don't have my code in a public repository at this time (private work project).

I started by re-implementing the webcam transfer learning example and substituting the camera class with files. That was a big help with building the decapitated mobilenet model, doing the training, and getting predictions. However, the data controller class was a major problem once you start adding hundreds of images. I believe it was taking around 90 minutes to load 12,000 280x280px images. This was due to the way it was dealing with the memory allocation (and re-allocation) for the arrays. I referred to the mnist-node example for a much better way to load the images. Once I re-implemented the data class using the mnist-node approach, my data loading time was on par with the python image retraining example.

joel1725 commented 5 years ago

thanks @adwellj for answering

I have been using the webcam transfer learning example from the beginning, I have done it completely using javascrit in the browser but now using only with nodejs is that I have encountered some problems, like this one showing that getLager is not a function, no matter how I put it, it just keeps showing that and I can not find anything on the internet to help me solve this problem and no idea why it is generated.

adwellj commented 5 years ago

@joel1725, can you show the error message that you're getting and the relevant code surrounding the line that it's generated from?

I've just recently started learning Node and TF, so I lack a lot of experience, but I can try to help.

tafsiri commented 5 years ago

@joel1725 In your code try mobilenet.model.getLayer(). The @tensorflow-models/mobilenet package wraps the actual mobilenet model in a class that provides some utility functions for doing predictions without needing to convert things to tensors, but hides the underlying tfjs api.

joel1725 commented 5 years ago

Excellent thanks @tafsiri this worked correctly......

Also thanks @adwellj for your interest in solving this problem, I was writing you the error until I saw the comment of @tafsiri.

Once I finish my project I will make it public on github cuz onTesorFlow and Nodejs I think there are few examples available.

Thanks.

adwellj commented 5 years ago

@joel1725, you're welcome! Hit me up if you get in to any other snags. There were a few other obstacles that I ran in to that I can help you with.

I've been meaning to try and put this in to a public repository, so that others could benefit from it. I'll see if I can find some time in the next few days to do that, and will share with you.

joel1725 commented 5 years ago

@adwellj It would be great to be able to see your work, be sure to share it with me, thank you.

adwellj commented 5 years ago

@joel1725, check out my repo: https://github.com/adwellj/node-tfjs-retrain

joel1725 commented 5 years ago

@joel1725, check out my repo: https://github.com/adwellj/node-tfjs-retrain

@adwellj An incredible project, it's great I can combine some ideas with the one I'm creating, excellent work, has thrown some lights. When I upload the one I'm doing, I'll show you.