@@ -1237,7 +1237,6 @@ describeMathCPUAndGPU('Saving+loading model with optimizer', () => {
12371237 return null ;
12381238 } ) , { includeOptimizer : true } ) ;
12391239
1240- const modelTopology = savedArtifacts . modelTopology as ConfigDict ;
12411240 const trainingConfig = savedArtifacts . trainingConfig ;
12421241 expect ( trainingConfig [ 'loss' ] ) . toEqual ( 'mean_squared_error' ) ;
12431242
@@ -1254,8 +1253,7 @@ describeMathCPUAndGPU('Saving+loading model with optimizer', () => {
12541253 expect ( weightData . byteLength ) . toEqual ( 4 * 8 + 4 * 1 + 4 ) ;
12551254
12561255 // Load the model back, with the optimizer.
1257- const model2 = await tfl . loadLayersModel (
1258- io . fromMemory ( modelTopology , weightSpecs , weightData , trainingConfig ) ) ;
1256+ const model2 = await tfl . loadLayersModel ( io . fromMemory ( savedArtifacts ) ) ;
12591257 expect ( model2 . optimizer . getConfig ( ) [ 'learningRate' ] ) . toEqual ( learningRate ) ;
12601258
12611259 const optimizer1Weights = await model1 . optimizer . getWeights ( ) ;
@@ -1295,7 +1293,6 @@ describeMathCPUAndGPU('Saving+loading model with optimizer', () => {
12951293 return null ;
12961294 } ) , { includeOptimizer : true } ) ;
12971295
1298- const modelTopology = savedArtifacts . modelTopology as ConfigDict ;
12991296 const trainingConfig = savedArtifacts . trainingConfig ;
13001297 expect ( trainingConfig [ 'loss' ] ) . toEqual ( 'mean_squared_error' ) ;
13011298
@@ -1317,8 +1314,7 @@ describeMathCPUAndGPU('Saving+loading model with optimizer', () => {
13171314 expect ( weightData . byteLength ) . toEqual ( 4 + 4 * 8 * 3 + 4 * 1 * 3 ) ;
13181315
13191316 // Load the model back, with the optimizer.
1320- const model2 = await tfl . loadLayersModel (
1321- io . fromMemory ( modelTopology , weightSpecs , weightData , trainingConfig ) ) ;
1317+ const model2 = await tfl . loadLayersModel ( io . fromMemory ( savedArtifacts ) ) ;
13221318 expect ( model2 . optimizer . getConfig ( ) [ 'learningRate' ] ) . toEqual ( learningRate ) ;
13231319 expect ( model2 . optimizer . getConfig ( ) [ 'decay' ] ) . toEqual ( decay ) ;
13241320
@@ -1358,7 +1354,6 @@ describeMathCPUAndGPU('Saving+loading model with optimizer', () => {
13581354 return null ;
13591355 } ) , { includeOptimizer : true } ) ;
13601356
1361- const modelTopology = savedArtifacts . modelTopology as ConfigDict ;
13621357 const trainingConfig = savedArtifacts . trainingConfig ;
13631358 expect ( trainingConfig [ 'loss' ] ) . toEqual ( 'mean_squared_error' ) ;
13641359
@@ -1380,8 +1375,7 @@ describeMathCPUAndGPU('Saving+loading model with optimizer', () => {
13801375 expect ( weightData . byteLength ) . toEqual ( 4 + 4 * 8 * 3 + 4 * 1 * 3 ) ;
13811376
13821377 // Load the model back, with the optimizer.
1383- const model2 = await tfl . loadLayersModel (
1384- io . fromMemory ( modelTopology , weightSpecs , weightData , trainingConfig ) ) ;
1378+ const model2 = await tfl . loadLayersModel ( io . fromMemory ( savedArtifacts ) ) ;
13851379 expect ( model2 . optimizer . getConfig ( ) [ 'learningRate' ] ) . toEqual ( learningRate ) ;
13861380
13871381 const optimizer1Weights = await model1 . optimizer . getWeights ( ) ;
@@ -1421,7 +1415,6 @@ describeMathCPUAndGPU('Saving+loading model with optimizer', () => {
14211415 return null ;
14221416 } ) , { includeOptimizer : true } ) ;
14231417
1424- const modelTopology = savedArtifacts . modelTopology as ConfigDict ;
14251418 const trainingConfig = savedArtifacts . trainingConfig ;
14261419 expect ( trainingConfig [ 'loss' ] ) . toEqual ( 'mean_squared_error' ) ;
14271420
@@ -1441,8 +1434,7 @@ describeMathCPUAndGPU('Saving+loading model with optimizer', () => {
14411434 expect ( weightData . byteLength ) . toEqual ( 4 + 4 * 8 * 2 + 4 * 1 * 2 ) ;
14421435
14431436 // Load the model back, with the optimizer.
1444- const model2 = await tfl . loadLayersModel (
1445- io . fromMemory ( modelTopology , weightSpecs , weightData , trainingConfig ) ) ;
1437+ const model2 = await tfl . loadLayersModel ( io . fromMemory ( savedArtifacts ) ) ;
14461438 expect ( model2 . optimizer . getConfig ( ) [ 'learningRate' ] ) . toEqual ( learningRate ) ;
14471439 expect ( model2 . optimizer . getConfig ( ) [ 'initialAccumulatorValue' ] )
14481440 . toEqual ( initialAccumulatorValue ) ;
@@ -1485,7 +1477,6 @@ describeMathCPUAndGPU('Saving+loading model with optimizer', () => {
14851477 return null ;
14861478 } ) , { includeOptimizer : true } ) ;
14871479
1488- const modelTopology = savedArtifacts . modelTopology as ConfigDict ;
14891480 const trainingConfig = savedArtifacts . trainingConfig ;
14901481 expect ( trainingConfig [ 'loss' ] ) . toEqual ( 'mean_squared_error' ) ;
14911482
@@ -1507,8 +1498,7 @@ describeMathCPUAndGPU('Saving+loading model with optimizer', () => {
15071498 expect ( weightData . byteLength ) . toEqual ( 4 + 4 * 8 * 3 + 4 * 1 * 3 ) ;
15081499
15091500 // Load the model back, with the optimizer.
1510- const model2 = await tfl . loadLayersModel (
1511- io . fromMemory ( modelTopology , weightSpecs , weightData , trainingConfig ) ) ;
1501+ const model2 = await tfl . loadLayersModel ( io . fromMemory ( savedArtifacts ) ) ;
15121502 expect ( model2 . optimizer . getConfig ( ) [ 'learningRate' ] ) . toEqual ( learningRate ) ;
15131503 expect ( model2 . optimizer . getConfig ( ) [ 'beta1' ] ) . toEqual ( beta1 ) ;
15141504 expect ( model2 . optimizer . getConfig ( ) [ 'beta2' ] ) . toEqual ( beta2 ) ;
@@ -1547,7 +1537,6 @@ describeMathCPUAndGPU('Saving+loading model with optimizer', () => {
15471537 return null ;
15481538 } ) , { includeOptimizer : true } ) ;
15491539
1550- const modelTopology = savedArtifacts . modelTopology as ConfigDict ;
15511540 const trainingConfig = savedArtifacts . trainingConfig ;
15521541 expect ( trainingConfig [ 'loss' ] ) . toEqual ( 'mean_squared_error' ) ;
15531542
@@ -1569,8 +1558,7 @@ describeMathCPUAndGPU('Saving+loading model with optimizer', () => {
15691558 expect ( weightData . byteLength ) . toEqual ( 4 + 4 * 8 * 3 + 4 * 1 * 3 ) ;
15701559
15711560 // Load the model back, with the optimizer.
1572- const model2 = await tfl . loadLayersModel (
1573- io . fromMemory ( modelTopology , weightSpecs , weightData , trainingConfig ) ) ;
1561+ const model2 = await tfl . loadLayersModel ( io . fromMemory ( savedArtifacts ) ) ;
15741562 expect ( model2 . optimizer . getConfig ( ) [ 'learningRate' ] ) . toEqual ( 1e-3 ) ;
15751563
15761564 const optimizer1Weights = await model1 . optimizer . getWeights ( ) ;
@@ -1610,7 +1598,6 @@ describeMathCPUAndGPU('Saving+loading model with optimizer', () => {
16101598 return null ;
16111599 } ) , { includeOptimizer : true } ) ;
16121600
1613- const modelTopology = savedArtifacts . modelTopology as ConfigDict ;
16141601 const trainingConfig = savedArtifacts . trainingConfig ;
16151602 expect ( trainingConfig [ 'loss' ] ) . toEqual ( 'mean_squared_error' ) ;
16161603
@@ -1630,8 +1617,7 @@ describeMathCPUAndGPU('Saving+loading model with optimizer', () => {
16301617 expect ( weightData . byteLength ) . toEqual ( 4 + 4 * 8 * 2 + 4 * 1 * 2 ) ;
16311618
16321619 // Load the model back, with the optimizer.
1633- const model2 = await tfl . loadLayersModel (
1634- io . fromMemory ( modelTopology , weightSpecs , weightData , trainingConfig ) ) ;
1620+ const model2 = await tfl . loadLayersModel ( io . fromMemory ( savedArtifacts ) ) ;
16351621 expect ( model2 . optimizer . getConfig ( ) [ 'learningRate' ] ) . toEqual ( learningRate ) ;
16361622
16371623 const optimizer1Weights = await model1 . optimizer . getWeights ( ) ;
@@ -1675,15 +1661,11 @@ describeMathCPUAndGPU('Saving+loading model with optimizer', () => {
16751661 return null ;
16761662 } ) , { includeOptimizer : true } ) ;
16771663
1678- const modelTopology = savedArtifacts . modelTopology as ConfigDict ;
16791664 const trainingConfig = savedArtifacts . trainingConfig ;
16801665 expect ( trainingConfig [ 'loss' ] ) . toEqual ( 'categorical_crossentropy' ) ;
16811666 expect ( trainingConfig [ 'metrics' ] ) . toEqual ( [ 'acc' ] ) ;
16821667
1683- const weightSpecs = savedArtifacts . weightSpecs ;
1684- const weightData = savedArtifacts . weightData ;
1685- const model2 = await tfl . loadLayersModel (
1686- io . fromMemory ( modelTopology , weightSpecs , weightData , trainingConfig ) ) ;
1668+ const model2 = await tfl . loadLayersModel ( io . fromMemory ( savedArtifacts ) ) ;
16871669 h = await model2 . fit ( xs , ys , { epochs : 1 } ) ;
16881670 expect ( h . history . loss . length ) . toEqual ( 1 ) ;
16891671 expect ( h . history . loss [ 0 ] ) . toBeCloseTo ( 1.086648 ) ;
@@ -1711,15 +1693,11 @@ describeMathCPUAndGPU('Saving+loading model with optimizer', () => {
17111693 return null ;
17121694 } ) , { includeOptimizer : true } ) ;
17131695
1714- const modelTopology = savedArtifacts . modelTopology as ConfigDict ;
17151696 const trainingConfig = savedArtifacts . trainingConfig ;
17161697 expect ( trainingConfig [ 'loss' ] ) . toEqual ( 'categorical_crossentropy' ) ;
17171698 expect ( trainingConfig [ 'metrics' ] ) . toEqual ( [ 'acc' ] ) ;
17181699
1719- const weightSpecs = savedArtifacts . weightSpecs ;
1720- const weightData = savedArtifacts . weightData ;
1721- const model2 = await tfl . loadLayersModel (
1722- io . fromMemory ( modelTopology , weightSpecs , weightData , trainingConfig ) ) ;
1700+ const model2 = await tfl . loadLayersModel ( io . fromMemory ( savedArtifacts ) ) ;
17231701
17241702 const xs = ones ( [ 4 , 8 ] ) ;
17251703 const ys = tensor2d ( [ [ 0 , 0 , 1 ] , [ 0 , 0 , 1 ] , [ 0 , 0 , 1 ] , [ 0 , 0 , 1 ] ] ) ;
@@ -1769,16 +1747,12 @@ describeMathCPUAndGPU('Saving+loading model with optimizer', () => {
17691747 return null ;
17701748 } ) , { includeOptimizer : true } ) ;
17711749
1772- const modelTopology = savedArtifacts . modelTopology as ConfigDict ;
17731750 const trainingConfig = savedArtifacts . trainingConfig ;
17741751 expect ( trainingConfig [ 'loss' ] ) . toEqual (
17751752 [ 'categorical_crossentropy' , 'binary_crossentropy' ] ) ;
17761753 expect ( trainingConfig [ 'metrics' ] ) . toEqual ( [ 'acc' ] ) ;
17771754
1778- const weightSpecs = savedArtifacts . weightSpecs ;
1779- const weightData = savedArtifacts . weightData ;
1780- const model2 = await tfl . loadLayersModel (
1781- io . fromMemory ( modelTopology , weightSpecs , weightData , trainingConfig ) ) ;
1755+ const model2 = await tfl . loadLayersModel ( io . fromMemory ( savedArtifacts ) ) ;
17821756
17831757 h = await model2 . fit ( xs , [ ys1 , ys2 ] , { epochs : 1 } ) ;
17841758 expect ( h . history . loss . length ) . toEqual ( 1 ) ;
0 commit comments