Open lukemovement opened 1 year ago
Hi, @lukemovement
Thank you for writing Node.JS wrapper for EfficientDet
and I was trying to run your code in my Mac
system with random person color jpg image
from the internet and converted index.ts
file to index.js
with the help of tsc
after that I ran node index.js
I'm getting below error messages, If have I missed something here please let me know ? or please guide me with the steps to run your above Node.JS wrapper for EfficientDet
code. Thank you!
Here is error log for your reference :
gaikwadrahul-macbookpro:test-7867 gaikwadrahul$ node index.js
/Users/gaikwadrahul/Desktop/TFJS/test-7867/index.js:250
var image = await fs_1.promises.readFile(imagePath);
^^^^^
SyntaxError: await is only valid in async functions and the top level bodies of modules
at internalCompileFunction (node:internal/vm:73:18)
at wrapSafe (node:internal/modules/cjs/loader:1176:20)
at Module._compile (node:internal/modules/cjs/loader:1218:27)
at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)
at Module.load (node:internal/modules/cjs/loader:1117:32)
at Module._load (node:internal/modules/cjs/loader:958:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:23:47
Node.js v18.15.0
gaikwadrahul-macbookpro:test-7867 gaikwadrahul$
Hi, @lukemovement
Thank you for writing Node.JS wrapper for
EfficientDet
and I was trying to run your code in myMac
system with random personcolor jpg image
from the internet and convertedindex.ts
file toindex.js
with the help oftsc
after that I rannode index.js
I'm getting below error messages, If have I missed something here please let me know ? or please guide me with the steps to run your above Node.JS wrapper forEfficientDet
code. Thank you!Here is error log for your reference :
gaikwadrahul-macbookpro:test-7867 gaikwadrahul$ node index.js /Users/gaikwadrahul/Desktop/TFJS/test-7867/index.js:250 var image = await fs_1.promises.readFile(imagePath); ^^^^^ SyntaxError: await is only valid in async functions and the top level bodies of modules at internalCompileFunction (node:internal/vm:73:18) at wrapSafe (node:internal/modules/cjs/loader:1176:20) at Module._compile (node:internal/modules/cjs/loader:1218:27) at Module._extensions..js (node:internal/modules/cjs/loader:1308:10) at Module.load (node:internal/modules/cjs/loader:1117:32) at Module._load (node:internal/modules/cjs/loader:958:12) at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) at node:internal/main/run_main_module:23:47 Node.js v18.15.0 gaikwadrahul-macbookpro:test-7867 gaikwadrahul$
It sounds like you are using an older version of NodeJS than me. Use this to test the model instead.
const main = async () => {
// get object detection result
const imagePath = resolve(process.cwd(), "sample_in.jpg");
const image = await fs.readFile(imagePath);
const model = new EfficientDet();
await model.loadModel();
const result = await model.predict(image);
// draw boxes on image
const imageTensor = tf.node.decodeImage(image, 3) as tf.Tensor3D;
const highlightedImageTensor = await model.drawBoxesOnImage(
imageTensor,
result,
);
// write image to file
const output = await tf.node.encodeJpeg(
highlightedImageTensor as tf.Tensor3D,
);
await fs.writeFile(resolve(process.cwd(), "sample_out.jpg"), output);
};
main();
Hi, @lukemovement
Thank you for sharing your code and I tried your first code snippet with latest version of Node.js v18.17.0
, I'm still getting the same error message so now I'll assign this issue to our concerned team, they'll take look and appropriate action from their end. Thank you!
gaikwadrahul-macbookpro:test-7867 gaikwadrahul$ node index.js
/Users/gaikwadrahul/Desktop/TFJS/test-7867/index.js:250
var image = await fs_1.promises.readFile(imagePath);
^^^^^
SyntaxError: await is only valid in async functions and the top level bodies of modules
at internalCompileFunction (node:internal/vm:73:18)
at wrapSafe (node:internal/modules/cjs/loader:1178:20)
at Module._compile (node:internal/modules/cjs/loader:1220:27)
at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
at Module.load (node:internal/modules/cjs/loader:1119:32)
at Module._load (node:internal/modules/cjs/loader:960:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:23:47
Node.js v18.17.0
gaikwadrahul-macbookpro:test-7867 gaikwadrahul$
I have recently written a wrapper for EfficientDet but I don't really have the time to oversee getting it added as a PR due to personal commitments. The code seems to be fully functional. The input size of the model can be changed by replacing all instances of
1536
within the sample.Feel free to use or close the ticket :)