Skip to content

Commit

Permalink
add onProgress for loaders (#180)
Browse files Browse the repository at this point in the history
  • Loading branch information
syt123450 committed Feb 23, 2019
1 parent f01f8f4 commit 068097e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/loader/KerasLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ KerasLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
*/

load: async function() {

const loadedModel = await tf.loadLayersModel( this.url );
const loadedModel = await tf.loadLayersModel( this.url, this.tfjsLoadOption );

this.model.resource = loadedModel;

Expand Down
27 changes: 26 additions & 1 deletion src/loader/Loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,22 @@ function Loader( model, config ) {
*/

this.onCompleteCallback = undefined;

/**
* Store callback function fired periodically before load process is completed.
*
* @type { function }
*/

this.onProgressCallBack = undefined;

/**
* Tfjs LoadOption object.
*
* @type { Object }
*/

this.tfjsLoadOption = {};

// Load loader's basic configuration.

Expand All @@ -56,7 +72,16 @@ Loader.prototype = {
loadLoaderConfig: function( config ) {

if ( this.config !== undefined ) {


// If onProgress is defined by user, store it.

if ( config.onProgress !== undefined ) {

this.onProgressCallBack = config.onProgress;
this.tfjsLoadOption.onProgress = config.onProgress;

}

// If onComplete callback is defined by user, store it.

if ( config.onComplete !== undefined ) {
Expand Down
2 changes: 1 addition & 1 deletion src/loader/TfLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ TfLoader.prototype = Object.assign( Object.create( Loader.prototype ), {

load: async function() {

const loadedModel = await tf.loadGraphModel( this.modelUrl );
const loadedModel = await tf.loadGraphModel( this.modelUrl, this.tfjsLoadOption );

this.model.resource = loadedModel;

Expand Down
2 changes: 1 addition & 1 deletion src/loader/TfjsLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ TfjsLoader.prototype = Object.assign( Object.create( Loader.prototype ), {

load: async function() {

const loadedModel = await tf.loadLayersModel( this.url );
const loadedModel = await tf.loadLayersModel( this.url, this.tfjsLoadOption );

this.model.resource = loadedModel;

Expand Down

0 comments on commit 068097e

Please # to comment.