googlecreativelab / teachablemachine-community

Example code snippets and machine learning code for Teachable Machine
https://g.co/teachablemachine
Apache License 2.0
1.52k stars 686 forks source link

[BUG]: tmImage doesn't work and throws an error around fetch() #338

Open tadvas opened 1 year ago

tadvas commented 1 year ago

Describe the bug The goal is to create nodejs client, which will make predictions based on the model, generated by TM

However, it's not possible to use tmImage()

To Reproduce Steps to reproduce the behavior:

const tmImage = require('@teachablemachine/image');
const URL = 'https://teachablemachine.withgoogle.com/models/NujXJZDb4/';

async function init() {
  const modelURL = URL + 'model.json';
  const metadataURL = URL + 'metadata.json';

  model = await tmImage.load(modelURL, metadataURL);

  console.log('works')
}

init();

Stack trace: ReferenceError: fetch is not defined at /Users//Desktop/img/node_modules/@teachablemachine/image/dist/custom-mobilenet.js:153:17 at step (/Users//Desktop/img/node_modules/@teachablemachine/image/dist/custom-mobilenet.js:49:23) at Object.next (/Users//Desktop/img/node_modules/@teachablemachine/image/dist/custom-mobilenet.js:30:53) at /Users//Desktop/img/node_modules/@teachablemachine/image/dist/custom-mobilenet.js:24:71 at new Promise () at __awaiter (/Users//Desktop/img/node_modules/@teachablemachine/image/dist/custom-mobilenet.js:20:12) at processMetadata (/Users//Desktop/img/node_modules/@teachablemachine/image/dist/custom-mobilenet.js:147:52) at Object. (/Users//Desktop/img/node_modules/@teachablemachine/image/dist/custom-mobilenet.js:360:42) at step (/Users//Desktop/img/node_modules/@teachablemachine/image/dist/custom-mobilenet.js:49:23) at Object.next (/Users/***/Desktop/img/node_modules/@teachablemachine/image/dist/custom-mobilenet.js:30:53)

Expected behavior The function works w/o errors

codeandcats commented 1 year ago

@tadvas did you find a way to get this working in nodejs? If not, did you find another solution?