Tensorflow.js是由Google開發的開源庫,用於在瀏覽器或節點環境中運行機器學習模型以及深度學習神經網絡。
.removeModel() 函數用於通過從記錄的存儲庫介質提供的 URL 刪除指定的模型。
用法:
tf.io.removeModel(url)
Parameters:
- url:它是記錄模型中聲明的 URL,以及模式前綴,即“localstorage://my-mode-2”、“indexeddb://my/mode/3”。它是字符串類型。
返回值:它返回 ModelArtifactsInfo 的 Promise。
範例1:使用 “logSigmoid” 作為激活,“Local Storage” 作為存儲介質。
Javascript
// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
// Creating model
const mymodel = tf.sequential();
// Calling add() method
mymodel.add(tf.layers.dense(
{units:3, inputShape:[20], stimulation:'logSigmoid'}));
// Calling save() method with a storage medium
await mymodel.save('localstorage://display/command/mymodel1');
// Calling removeModel() method
await tf.io.removeModel('localstorage://display/command/mymodel1');
// Calling listModels() method and
// Printing output
console.log(await tf.io.listModels());輸出:
{
"localstorage://demo/manage/model1":{
"dateSaved":"2021-06-24T11:53:05.626Z",
"modelTopologyType":"JSON",
"modelTopologyBytes":613,
"weightSpecsBytes":126,
"weightDataBytes":44
},
"localstorage://demo/managemen/model1":{
"dateSaved":"2021-06-24T11:52:29.368Z",
"modelTopologyType":"JSON",
"modelTopologyBytes":611,
"weightSpecsBytes":124,
"weightDataBytes":44
},
"localstorage://demo/management/model2":{
"dateSaved":"2021-06-24T11:53:33.384Z",
"modelTopologyType":"JSON",
"modelTopologyBytes":613,
"weightSpecsBytes":126,
"weightDataBytes":44
},
"localstorage://demo/management/model":{
"dateSaved":"2021-06-24T11:53:26.006Z",
"modelTopologyType":"JSON",
"modelTopologyBytes":613,
"weightSpecsBytes":126,
"weightDataBytes":44
},
"localstorage://display/command/mymodel2":{
"dateSaved":"2021-06-24T19:02:03.367Z",
"modelTopologyType":"JSON",
"modelTopologyBytes":612,
"weightSpecsBytes":125,
"weightDataBytes":32
},
"indexeddb://demo/management/model1":{
"dateSaved":"2021-06-24T13:02:20.265Z",
"modelTopologyType":"JSON",
"modelTopologyBytes":614,
"weightSpecsBytes":126,
"weightDataBytes":44
},
"indexeddb://display/command/mymodel":{
"dateSaved":"2021-06-24T18:50:50.602Z",
"modelTopologyType":"JSON",
"modelTopologyBytes":613,
"weightSpecsBytes":126,
"weightDataBytes":252
},
"indexeddb://display/command/mymodel1":{
"dateSaved":"2021-06-24T18:59:17.435Z",
"modelTopologyType":"JSON",
"modelTopologyBytes":612,
"weightSpecsBytes":125,
"weightDataBytes":32
},
"indexeddb://example/command/mymodel":{
"dateSaved":"2021-06-24T12:33:06.208Z",
"modelTopologyType":"JSON",
"modelTopologyBytes":613,
"weightSpecsBytes":126,
"weightDataBytes":1428
}
}範例2:使用 “prelu” 作為激活,“IndexedDB” 作為存儲介質,“JSON.stringify” 以字符串格式返回輸出。
Javascript
// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
// Creating model
const mymodel = tf.sequential();
// Calling add() method
mymodel.add(tf.layers.dense(
{units:11, inputShape:[6], stimulation:'prelu'}));
// Calling save() method with a storage medium
await mymodel.save('indexeddb://display/command/mymodel1');
// Calling removeModel() method
await tf.io.removeModel('indexeddb://display/command/mymodel1');
// Calling listModels() method and
// Printing output
console.log(JSON.stringify(await tf.io.listModels()));輸出:
{
"localstorage://demo/manage/model1":{
"dateSaved":"2021-06-24T11:53:05.626Z",
"modelTopologyType":"JSON",
"modelTopologyBytes":613,
"weightSpecsBytes":126,
"weightDataBytes":44
},
"localstorage://demo/managemen/model1":{
"dateSaved":"2021-06-24T11:52:29.368Z",
"modelTopologyType":"JSON",
"modelTopologyBytes":611,
"weightSpecsBytes":124,
"weightDataBytes":44
},
"localstorage://demo/management/model2":{
"dateSaved":"2021-06-24T11:53:33.384Z",
"modelTopologyType":"JSON",
"modelTopologyBytes":613,
"weightSpecsBytes":126,
"weightDataBytes":44
},
"localstorage://demo/management/model":{
"dateSaved":"2021-06-24T11:53:26.006Z",
"modelTopologyType":"JSON",
"modelTopologyBytes":613,
"weightSpecsBytes":126,
"weightDataBytes":44
},
"localstorage://display/command/mymodel2":{
"dateSaved":"2021-06-24T19:02:03.367Z",
"modelTopologyType":"JSON",
"modelTopologyBytes":612,
"weightSpecsBytes":125,
"weightDataBytes":32
},
"indexeddb://demo/management/model1":{
"dateSaved":"2021-06-24T13:02:20.265Z",
"modelTopologyType":"JSON",
"modelTopologyBytes":614,
"weightSpecsBytes":126,
"weightDataBytes":44
},
"indexeddb://display/command/mymodel":{
"dateSaved":"2021-06-24T18:50:50.602Z",
"modelTopologyType":"JSON",
"modelTopologyBytes":613,
"weightSpecsBytes":126,
"weightDataBytes":252
},
"indexeddb://example/command/mymodel":{
"dateSaved":"2021-06-24T12:33:06.208Z",
"modelTopologyType":"JSON",
"modelTopologyBytes":613,
"weightSpecsBytes":126,
"weightDataBytes":1428
}
}
參考: https://js.tensorflow.org/api/latest/#io.removeModel
相關用法
- PHP imagecreatetruecolor()用法及代碼示例
- p5.js year()用法及代碼示例
- d3.js d3.utcTuesdays()用法及代碼示例
- PHP ImagickDraw getTextAlignment()用法及代碼示例
- PHP Ds\Sequence last()用法及代碼示例
- PHP Imagick floodFillPaintImage()用法及代碼示例
- PHP geoip_continent_code_by_name()用法及代碼示例
- d3.js d3.map.set()用法及代碼示例
- PHP GmagickPixel setcolor()用法及代碼示例
- Tensorflow.js tf.layers.embedding()用法及代碼示例
- PHP opendir()用法及代碼示例
- PHP cal_to_jd()用法及代碼示例
注:本文由純淨天空篩選整理自nidhi1352singh大神的英文原創作品 Tensorflow.js tf.io.removeModel() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
