thekevinscott/UpscalerJS

Unable to Use Non-default Models in Node

nminchow opened this issue · 2 comments

Describe the bug
I'm unable to specify models other than the default in a node environment. When I attempt to, I encounter the following:

node:internal/deps/undici/undici:6460
            throw new TypeError("Failed to parse URL from " + input, { cause: err });
                  ^

TypeError: Failed to parse URL from div2k-2x
    at new Request (node:internal/deps/undici/undici:6460:19)
    at Agent2.fetch (node:internal/deps/undici/undici:7157:29)
    ... 4 lines matching cause stack trace ...
    at step (D:\projects\image_upscaler\node_modules\@tensorflow\tfjs-core\dist\tf-core.node.js:123:27)
    at Object.next (D:\projects\image_upscaler\node_modules\@tensorflow\tfjs-core\dist\tf-core.node.js:72:53)
    at D:\projects\image_upscaler\node_modules\@tensorflow\tfjs-core\dist\tf-core.node.js:65:71
    at new Promise (<anonymous>) {
  [cause]: TypeError [ERR_INVALID_URL]: Invalid URL
      at new NodeError (node:internal/errors:372:5)
      at URL.onParseError (node:internal/url:563:9)
      at new URL (node:internal/url:643:5)
      at new Request (node:internal/deps/undici/undici:6458:25)
      at Agent2.fetch (node:internal/deps/undici/undici:7157:29)
      at Object.fetch (node:internal/deps/undici/undici:8060:22)
      at fetch (node:internal/bootstrap/pre_execution:194:25)
      at PlatformNode.fetch (D:\projects\image_upscaler\node_modules\@tensorflow\tfjs-core\dist\tf-core.node.js:7308:33)
      at HTTPRequest.<anonymous> (D:\projects\image_upscaler\node_modules\@tensorflow\tfjs-core\dist\tf-core.node.js:8172:55)
      at step (D:\projects\image_upscaler\node_modules\@tensorflow\tfjs-core\dist\tf-core.node.js:123:27) {
    input: 'div2k-2x',
    code: 'ERR_INVALID_URL'
  }
}

To Reproduce

nminchow/cmd-line-upscaler@0c89c43 on this branch introduces the error. I'm using node 18.0.0. The readme should allow you to test end-to-end locally. Let me know if there is any other context I can provide of if you are having trouble reproducing!

Thanks again for the bug report and the reproducible repo.

I think this is happening because the README is out of date. Try running this with:

const upscaler = new Upscaler({
  model: 'div2k/rdn-C3-D10-G64-G064-x2',
});

The full list of models can be seen here:

https://github.com/thekevinscott/UpscalerJS/blob/main/packages/upscalerjs/src/models.ts#L25

(Refer to the list of keys for the string to pass as the model parameter.)

I'll make a note to update the README with the correct list of models, but hopefully this should get you unblocked. Let me know if this works for you if you're still running into problems.


As an aside, I'm working towards a 1.0 release that will introduce a breaking change to how models are loaded.

Some justification can be found in this discussion and you can see progress on this PR:

#280

The code to load models was designed with a browser-exclusive use case in mind. With the introduction of Node support in 0.12.0 this has caused some issues which should be fixed by #280.

I've just released 1.0.0-beta.4 on NPM - this introduces the breaking change I mentioned above.

I'm going to close this issue, but please feel free to reopen if you're still seeing issues.