-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NodeJS Support #11
Comments
Upscaler already works in Node, both using tfjs-node and tfjs-node-gpu. I have it running using the CPU on OSX and the GPU on GKE. |
That’s great news! I tried searching the documentation for NodeJS, but came up empty. @danwexler Could you post a short example snippet? I tried following the quickstart, but ran into the error with HTMLImageElement from loadImage. Is there a flag or option I’m missing? |
Here's an example:
This code works in the browser and in Node. |
Thank you @danwexler I’ll try it out later this evening 😄 |
Let me know if you hit the realDivide issue I just posted, #12 |
Jumping onto this thread late - thank you @danwexler for providing guidance and runnable code! I'm not super familiar with TFJS in Node, but it sounds like y'all have been able to get it running. From a maintenance perspective it'd also be useful to:
We're currently running tests via Jest, which afaik is running in a Node-like environment, but we don't currently have any end-to-end tests. I believe Jest supports a browser-like environment, but it may be better to use something like Puppeteer to bootstrap an actual (headless) browser for tests. I'm also open if others have pointers on effectively testing JS libraries across both Node and the browser! |
Question for the group - would you (if willing) speak more to your use case for running in Node? For background, I assumed that the main use case for UpscalerJS would be via the browser, thus the lack of Node support out of the box. But if there's appetite for Node, it also makes me wonder whether the training code should be ported over; e.g., whether we should rewrite ESRGAN in Javascript so anyone could train it via Node. (As an aside, I'd love to make it easier for the community to contribute new models to the repo). |
I'm building a tool that uses TFJS in both the client and the server. It allows you to connect to your cloud storage, or load local files, and then apply a TF image processing model. You can run the models in either locally the browser or at scale on the cloud. It can also generate annotations (labels) which can be used to search for images or videos across your cloud storage drives. In my case, the browser is nice for testing out the operations locally, especially if the customer has a nice GPU. But even a nice GPU will take awhile on a movie file, and even longer if you want to process a folder filled with dozens of videos. That's when running in the cloud will be nice, since we can break up the video into batches of N frames and process them in parallel before re-encoding the final movie. |
That makes a lot of sense, and is very cool. Thanks @danwexler! |
Oh! I missed must’ve missed your last reply—whoops. I ended up learning to train custom models with https://github.com/victorca25/BasicSR I tried, but was unable to convert models to tfjs. @thekevinscott do you have any tips for converting models? |
Well, the main issue with that particular repo is it's using Pytorch, whereas you'd want a Tensorflow version. I've seen some folks discuss converting Pytorch models to Tensorflow (sometimes with ONNX as an in-between) but I haven't tried that myself. I'm not sure how the two codebases manage the core ops, so I could see it getting pretty hairy for anything non-trivial. Assuming you find a Tensorflow library, I did write a bit on the conversion process here. It's unfortunately a bit touch-and-go, particularly when a library implements custom ops (as the RRDN implementation in ESRGAN does) but it's certainly possible. |
Ahh alrighty. I was able to get from pytorch => onnx => tensorflow, but the tensorflow => tfjs failed. I also tried onnx => onnxjs, but that library isn’t compatible with the latest versions. |
Gotcha. Yeah, I haven't spent too much time with onnxjs, but with PyTorch picking up so much mindshare it may be worth a second look. |
Just wanted to follow up on the ONNX.js point - although commits are still being made to the repo, issues like this and this make it seem like there's some big gaps (and the last release was 7 months ago). So it's probably not worth supporting at the moment. Still, if we can figure out a way to go from Pytorch => tfjs, I think that'd be huge. I'm just not sure how feasible it will be. |
Yep, the lack of onnxjs support worried me. One other solution I didn’t mention was compiling to WASM. Pytorch has a c++ lib which can be ported. Since c++ is officially supported, there would be fewer edge cases compared to converting the models 3+ times to js. But my lack of c++ knowledge means that solution isn’t feasible for me. |
More alternatives include NodeJS C++ addons, with example implmentations: |
At the end i did the same. My solution was now converting the ONNX file to a tensorflow.js based on this i'm using now following lines:
|
Hi, it says : I would be really happy if you could help me out |
I haven't used this library for Node myself, I'm curious if others in the community can chime in with their solutions. I don't think Tensorflow.js supports paths to relative models like you're specifying. You may be able to try something like this - though I'm not 100% sure if the |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Node support is being tracked in #185. Canary releases are available on npm at |
Latest Node release is on This will be the last canary release before an official |
#185 was merged and Node support is live. UpscalerJS with Node support has been published on npm as Make sure to import the correct package for your system (and have the correct peer dependency of TFJS installed):
If you run into any bugs, please make a new issue! |
It’d be great to see support for running these upscaler models in NodeJS 😄
This will require changing how images are loaded (https://github.com/thekevinscott/UpscalerJS/blob/master/src/image.ts#L4). It would be great to support both image paths and buffers. There may be other changes too, but that’s where my error was thrown 😂
While UpscalerJS already supports webworkers, it may be good to use threads.js to support worker threads in NodeJS.
Supporting @tensorflow/tfjs-node would also substantially speed up processing. I have previously used this package, and found it difficult to navigate the native code dependencies and package size when using it in serverless functions. The package I made https://github.com/jlarmstrongiv/tfjs-node-lambda may provide some workarounds in serverless environments. Personally, I think being able to pass in the preferred version of tfjs (@tensorflow/tfjs, @tensorflow/tfjs-node, tfjs-node-lambda) as a constructor parameter would give a lot of flexibility.
I am interested in contributing. While I have experience with typescript and tensorflow, it would be great to collaborate with writing tests.
Anyway, thank you for making such a helpful library 👍
The text was updated successfully, but these errors were encountered: