r/TensorFlowJS • • Jun 01 '20

Blink detection with facemesh

3 Upvotes

Hi guys I've been experimenting with facemesh for about a month now and would like to know if it's possible to detect blinking of eyes using facemesh.

If not, then any suggestions on how I should approach this? Any help is appreciated:)


r/TensorFlowJS • • May 15 '20

Take an AR selfie using WebXR + tfjs BodyPix as body mask

Thumbnail
youtu.be
3 Upvotes

r/TensorFlowJS • • May 12 '20

TensorFlow.js Show & Tell #2: Sat 30th May @ 5PM JST (Europe / Asia friendly time)

Post image
3 Upvotes

r/TensorFlowJS • • Apr 07 '20

Intro to Facial Machine Learning in JavaScript

Thumbnail
kickstarter.com
3 Upvotes

r/TensorFlowJS • • Mar 24 '20

best resources/courses to learn tensorflowJS?

3 Upvotes

r/TensorFlowJS • • Mar 24 '20

Real-time Clothing size body measurement estimator using TensorFlow.js

Thumbnail
youtu.be
3 Upvotes

r/TensorFlowJS • • Feb 05 '20

I was looking at the new Tensorflow.js github repo and I was kinda lost trying to figure out how I would actually use it and then it hit me. What if my contribution to AI was to build a friendly easy to use User Interface? What you guys think? Useful?

3 Upvotes

r/TensorFlowJS • • Aug 14 '19

Plotting TensorFlow.js Activation Functions

Thumbnail
tech.courses
3 Upvotes

r/TensorFlowJS • • Aug 10 '19

TensorFlow.js 1.0 (talk at TensorFlow Dev Summit '19)

Thumbnail
youtube.com
3 Upvotes

r/TensorFlowJS • • Jan 25 '25

Web AI Spotify DJ - powered by client side Google Gemma 2 in Chrome!

Thumbnail
youtube.com
2 Upvotes

r/TensorFlowJS • • Oct 18 '24

load model

2 Upvotes

Hello,

I am currently working on a project to help people with disabilities to communicate better. For this I have built a React app and already trained an LSTM model in pyhton, but I am having problems loading the model into the app.

My Python code:

def create_model():

model = Sequential()

model.add(Embedding(input_dim=total_words, output_dim=100, input_length=max_sequence_len - 1))

model.add(Bidirectional(LSTM(150)))

model.add(Dense(total_words, activation='softmax'))

adam = Adam(learning_rate=0.01)

model.compile(loss='categorical_crossentropy', optimizer=adam, metrics=['accuracy'])

return model

The conversion:

! tensorflowjs_converter --input_format=keras {model_file} {js_model_dir}

The code to load:

const [model, setModel] = useState<tf.LayersModel | null>(null);

// Function for loading the model

const loadModel = async () => {

try {

const loadedModel = await tf.loadLayersModel('/gru_js/model.json'); // Customized path

setModel(loadedModel);

console.log('Model loaded successfully:', loadedModel);

} catch (error) {

console.error('Error loading the model:', error);

}

};

// Load model when loading the component

useEffect(() => {

loadModel();

}, []);

And the error that occurs:

NlpModelArea.tsx:14 Error loading the model: _ValueError: An InputLayer should be passed either a `batchInputShape` or an `inputShape`. at new InputLayer

I am happy about every comment


r/TensorFlowJS • • Aug 31 '24

Help! TensorFlow Error in Node.js Test for Reinforcement Learning Trading Bot (Using Tidy)

2 Upvotes

Hi everyone,

I'm developing a reinforcement learning trading bot in Node.js, and I've encountered a TensorFlow.js error during testing that I can't seem to resolve. Here’s the error:

RUNS  tests/reinforcement.test.js

/Users/nsursock/Sites/trading/hybrid-trading-bot/node_modules/@tensorflow/tfjs-core/dist/tf-core.node.js:4522

var srcBackend = info.backend;

\^



TypeError: Cannot read properties of undefined (reading 'backend')

This error happens when running my tests, and I suspect it might be related to the early disposal of tensors, but I’m not entirely sure. I’ve been using the `tidy` function to manage memory, so that could also be playing a role.

Project details:

  • Node.js project for a reinforcement learning trading bot

  • TensorFlow.js with `tidy` for memory management

  • Error occurs in `tests/reinforcement.test.js`

Has anyone experienced something similar or have ideas on how to fix this? Any help would be greatly appreciated!

Thanks!

        function learn() {
            console.log("Learning triggered with batch size:", batchSize, memory.length);
    
            const states = memory.map(m => m.state);
            const actions = memory.map(m => m.action);
            const rewards = memory.map(m => m.reward);
            const nextStates = memory.map(m => m.nextState);
            const dones = memory.map(m => m.done);
    
            tf.tidy(() => {
                const stateTensor = tf.tensor2d(states);
                const actionTensor = tf.tensor1d(actions, 'int32');
                const rewardTensor = tf.tensor1d(rewards);
                const nextStateTensor = tf.tensor2d(nextStates);
    
                console.log("Learning tensors created.");
    
                
    // Critic update
                const valueTensor = critic.predict(stateTensor);
                const nextValueTensor = critic.predict(nextStateTensor).reshape([nextStateTensor.shape[0]]);
                console.log("Value and next value predictions made.");
    
                const tdTargets = rewardTensor.add(nextValueTensor.mul(gamma).mul(tf.scalar(1).sub(tf.tensor1d(dones))));
                console.log("TD targets calculated. Shape:", tdTargets.shape);
    
                const tdTargetsReshaped = tdTargets.reshape([tdTargets.shape[0], 1]);
                console.log("TD targets reshaped. Shape:", tdTargetsReshaped.shape);
    
                critic.trainOnBatch(stateTensor, tdTargetsReshaped);
                console.log("Critic updated with TD targets.");
    
                
    // Actor update
                const advantageTensor = tdTargetsReshaped.sub(valueTensor);
                const actionProbs = actor.predict(stateTensor);
                const actionProbsTensor = tf.gather(actionProbs, actionTensor, 1);
    
                console.log("Advantage calculated. Action probabilities gathered.");
    
                const oldProbsTensor = actionProbsTensor.clone();  
    // Placeholder for storing old probs (for PPO clipping)
                const ratioTensor = actionProbsTensor.div(oldProbsTensor);
    
                console.log("Ratio for PPO clipping calculated. Ratio shape:", ratioTensor.shape);
    
                const clipTensor = tf.clipByValue(ratioTensor, 1 - clipRatio, 1 + clipRatio);
                const loss = tf.minimum(ratioTensor.mul(advantageTensor), clipTensor.mul(advantageTensor)).mean().mul(-1);
    
    
    
                const checkGradients = (inputs, targets) => {
                    tf.tidy(() => {
                        console.log("Checking gradients", inputs.arraySync(), targets.arraySync());
                        const tape = tf.GradientTape();
                        console.log("Tape", tape);
                        const loss = lossFunction(inputs, targets);
                        console.log("Loss", loss.arraySync());
                        const gradients = tape.gradient(loss, agent.model.trainableVariables);
    
                        console.log("Gradients", gradients.arraySync());
                        gradients.forEach((grad, index) => {
                            if (grad === null) {
                                console.warn(`Gradient at index ${index} is null`);
                            } else if (tf.any(tf.isNaN(grad)).dataSync()[0]) {
                                console.error(`Gradient at index ${index} has NaN values`);
                            }
                        });
                    });
                };
    
                
    // Example usage of checkGradients
                const inputs = tf.tensor2d(states); 
    // Replace with actual input data
                const targets = advantageTensor; 
    // Replace with actual target data
                checkGradients(inputs, targets);
    
    
    
    
                
    // Entropy bonus
                const entropy = actionProbsTensor.mul(tf.log(actionProbsTensor)).sum().mul(-1);
                const totalLoss = loss.add(entropy.mul(entropyCoefficient));
    
                console.log("Loss calculated for actor update with entropy bonus.");
    
                actor.trainOnBatch(stateTensor, totalLoss);
                console.log("Actor updated with loss and entropy bonus.");
            });
        }

r/TensorFlowJS • • Jul 17 '24

Seeking Pair Programming Partner(s) for a Node.js and TensorFlow.js open-source project

2 Upvotes

Hello everyone,

I hope you're all doing well!

I'm currently working on a couple of exciting open-source projects that involve Node.js and TensorFlow.js, and I'm looking for some enthusiastic and knowledgeable individuals to join me in pair programming. Here’s a bit more about what I’m working on and what I’m looking for:

About the Projects:

  1. Node.js Application Development:

    • Building scalable and efficient back-end services.

    • Integrating with various APIs and databases.

    • Ensuring high performance and responsiveness.

  2. TensorFlow.js Projects:

    • Implementing machine learning models directly in the browser or on Node.js servers.

    • Developing innovative AI-driven features.

    • Working with data preprocessing, model training, and deployment.

Current Implementation:

I have a working codebase that leverages TensorFlow.js for machine learning tasks. The API I’ve built allows for:

  • Collecting Measurement Data: The API can collect and process measurement data.

  • Building Custom ML Models: It can build models with adjustable hyper-parameters.

  • Training Data: The API can train the collected data using the custom models.

  • Classifying Measurements: It can classify unknown measurements based on the trained model. For example, if you request to classify -5100.00, the API returns the class "Negative". If you request 23.10, the API returns the class "Positive".

What I Need Help With:

While the current implementation works well as a proof of concept, I need help to extend the capabilities of the API to predict time series data instead of just classification. Specifically:

  • Enhancing the Model: Adjusting the current model to handle time series predictions.

  • Implementing LSTM and Other Networks: Setting up the model to use LSTM or other appropriate networks for time series.

  • Node.js and TensorFlow.js Expertise: I need guidance and support on the implementation as I’m a beginner and not entirely confident in my current code, even though it has produced good results so far.

What I’m Looking For:

  • Experience with Node.js: You should be comfortable with JavaScript and have a good understanding of Node.js and its ecosystem.

  • Familiarity with TensorFlow.js: Some experience with TensorFlow.js or a willingness to learn quickly.

  • Collaborative Mindset: Open to sharing knowledge, brainstorming ideas, and solving problems together.

  • Hopefully living in the west-EU area so that timezone is not complicated to handle

What You’ll Get:

  • Credits on the open source project: this is the bare minimal !!

  • Fun and Engaging Collaboration: Enjoy the process of building something great together.

  • I'm sorry I can't offer much more ...

If you’re interested, please drop a comment below or send me a direct message with a bit about yourself, your experience, and why you’d like to join. Looking forward to collaborating and building something amazing together!

Thank you very much!


r/TensorFlowJS • • Jul 06 '24

Web AI Demo: Does Video Contain - enable videos to watch themselves to perform useful work

Thumbnail
youtube.com
2 Upvotes

r/TensorFlowJS • • May 01 '24

How stable is tf.js for doing reinforcement learning stuffs

Thumbnail self.reinforcementlearning
2 Upvotes

r/TensorFlowJS • • Dec 15 '23

UAL to teach TensorFlow.js to students in collaboration with Google

Thumbnail
arts.ac.uk
2 Upvotes

r/TensorFlowJS • • Nov 09 '23

Pattern Recognition

2 Upvotes

Hello everyone, I need to recognize a pattern from an image. It must be useful for every image which includes a pattern. I have no idea about how i can start. Are there anyone to give some ideas to me? I'm open for every idea. Thanks in advance.


r/TensorFlowJS • • Nov 05 '23

Creating a Twin Delayed Deep Deterministic Policy Gradient (TD3)

2 Upvotes

Hi everyone. I've been using ChatGPT(3.5) to help me convert Python code using TD3 into JavaScript with TensorFlow JS. This is for the community and not for personal gain.

My goal is to make a basic blueprint for the community to use on TensorFlow JS projects. When complete, the agent will be displayed on an HTML5 canvas walking toward a civilian for good reward~~, while avoiding a zombie (negative penalty).~~

The bad news: I'm not a professional of Python or Tensorflow JS, and ChatGPT is shakey when it comes to complex tasks. At the moment the agent isn't learning yet, but it's running without errors. I expect the code has mistakes I don't even know about yet.

The good news: I have made a lot of progress and have a GitHub repository set up for the community to learn from and use the project: https://github.com/CloudZero2049/TD3-TensorFlowJS

I would love for anyone who knows the intricacies of TD3 (DDPG is a close relative), and TensorFlow JS to help me get this blueprint project setup for everyone =) The README on GitHub has more info and resources.


r/TensorFlowJS • • Aug 26 '23

Machine learning in medicine using JavaScript: building web apps using TensorFlow.js for interpreting biomedical datasets

Thumbnail
medrxiv.org
2 Upvotes

r/TensorFlowJS • • Jul 27 '23

Model requests tensor of size [null,100,100,3], but I don't know how to give that to it

2 Upvotes

Crosspost from my stackoverflow.

I am sure the solution is out there somewhere, but I have been unable to find it. I originally trained the model in normal tensorflow, but it is being used in tensorflowjs after being converted. My current error is

Uncaught (in promise) Error: Size(30000) must match the product of shape 100,100,3

Though I have had many others through my attempts.

My code right now is

function preprocess(imageData) {     //const img_arr = cv.imread(imageData); let inputTensor = tf.browser.fromPixels(imageData);     const offset = tf.scalar(255.0);     const normalized = tf.scalar(1.0).sub(inputTensor.div(offset));     const batchInputShape = [100, 100, 3];     const flattenedInput = tf.reshape(normalized, [batchInputShape]);     console.log(flattenedInput.shape);     return flattenedInput;  

The result of this function is then fed into my model, which produces the error. I am sure the solution is obvious but I have been unable to find it.

I have also tried

const batchInputShape = [null, 100, 100, 3]; const flattenedInput = tf.reshape(normalized, [batchInputShape, -1]);  

Though that did not fair any better.


r/TensorFlowJS • • Jun 04 '23

Web ML Monthly #13: Visual Blocks, Tech Talks, and Figma plugins

Thumbnail
linkedin.com
2 Upvotes

r/TensorFlowJS • • May 28 '23

Help with bounding boxes on webcam stream

2 Upvotes

Hi,

https://pastecode.io/s/ghn163on

I working through some examples in a colab. The code above takes a webcam stream, applies bounding boxes then prints an image. Is it possible to have the bounding boxes overlay on the live video stream? I can't seem to find code to do that.

Thanks


r/TensorFlowJS • • May 26 '23

How to Improve Performance in Transfer Learning

Thumbnail wordsabout.dev
2 Upvotes

r/TensorFlowJS • • May 04 '23

Google IO: What's new with Web ML in 2023?

Thumbnail
io.google
2 Upvotes