Skip to content
This repository was archived by the owner on Oct 17, 2021. It is now read-only.

No-scheme relative path should be routed to HTTP handler only in browser #234

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions src/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
/* Original source keras/models.py */

// tslint:disable:max-line-length
import {doc, io, Scalar, serialization, Tensor} from '@tensorflow/tfjs-core';
import {doc, ENV, io, Scalar, serialization, Tensor} from '@tensorflow/tfjs-core';

import * as K from './backend/tfjs_backend';
import {History} from './callbacks';
Expand Down Expand Up @@ -201,14 +201,25 @@ export async function loadModelInternal(pathOrIOHandler: string|
io.IOHandler): Promise<Model> {
if (typeof pathOrIOHandler === 'string') {
const handlers = io.getLoadHandlers(pathOrIOHandler);
if (handlers.length === 0) {
if (handlers.length === 0 && ENV.get('IS_BROWSER')) {
// For backward compatibility: if no load handler can be found,
// assume it is a relative http path.
// assume it is a relative http path. This applies only to the
// browser environment.
handlers.push(io.browserHTTPRequest(pathOrIOHandler));
} else if (handlers.length > 1) {
}
if (handlers.length > 1) {
throw new ValueError(
`Found more than one (${handlers.length}) load handlers for ` +
`URL '${pathOrIOHandler}'`);
} else if (handlers.length === 0) {
let errorMsg =
`Cannot find any load handlers for path string '${pathOrIOHandler}'.`;
if (ENV.get('IS_NODE')) {
errorMsg +=
' For Node.js, a URL scheme (e.g., file://, http://, https://)' +
'is required.';
}
throw new ValueError(errorMsg);
}
pathOrIOHandler = handlers[0];
}
Expand Down Expand Up @@ -326,8 +337,8 @@ export class Sequential extends Model {
* ```
* @param layer Layer instance.
*
* @exception ValueError In case the `layer` argument does not know its input
* shape.
* @exception ValueError In case the `layer` argument does not know its
* input shape.
* @exception ValueError In case the `layer` argument has multiple output
* tensors, or is already connected somewhere else (forbidden in
* `Sequential` models).
Expand Down