张量流 |如何获得两个训练模型之间的模型增量
TensorFlowJs | How To Get Model Delta Between Two Trained Models
我有 (2) 个相同的型号:
- Model1 = 在基础数据集上训练
- 模型 2 = 在基础数据集 + 附加数据集上训练
如何使用 TensorFlowJs 获得 Model1 和 Model2 之间的增量?
const Model1 = tf.sequential();
Model1.add(tf.layers.dense({units: 50, inputShape: [1], activation: 'relu', kernel_regularizer: 'l2'}));
Model1.add(tf.layers.dense({units: 1, inputShape: [1], activation: 'sigmoid'}));
Model1.compile({loss: 'binaryCrossentropy', optimizer: 'rmsprop', metrics: 'accuracy'});
const Model2 = tf.sequential();
Model2.add(tf.layers.dense({units: 50, inputShape: [1], activation: 'relu', kernel_regularizer: 'l2'}));
Model2.add(tf.layers.dense({units: 1, inputShape: [1], activation: 'sigmoid'}));
Model2.compile({loss: 'binaryCrossentropy', optimizer: 'rmsprop', metrics: 'accuracy'});
# train/fit Model1 with base dataset
# train/fit Model2 with base dataset + additional dataset
# get difference between Model1 and Model2 with TensorFlowJs here
我希望得到 Model1 和 Model2 之间的权重差异
要获得模型的权重,可以使用 getWeights for each layer. The answer 描述如何做到这一点。
检索两个模型的权重后,可以使用 sub 运算符找出两者之间的差异。
我有 (2) 个相同的型号:
- Model1 = 在基础数据集上训练
- 模型 2 = 在基础数据集 + 附加数据集上训练
如何使用 TensorFlowJs 获得 Model1 和 Model2 之间的增量?
const Model1 = tf.sequential();
Model1.add(tf.layers.dense({units: 50, inputShape: [1], activation: 'relu', kernel_regularizer: 'l2'}));
Model1.add(tf.layers.dense({units: 1, inputShape: [1], activation: 'sigmoid'}));
Model1.compile({loss: 'binaryCrossentropy', optimizer: 'rmsprop', metrics: 'accuracy'});
const Model2 = tf.sequential();
Model2.add(tf.layers.dense({units: 50, inputShape: [1], activation: 'relu', kernel_regularizer: 'l2'}));
Model2.add(tf.layers.dense({units: 1, inputShape: [1], activation: 'sigmoid'}));
Model2.compile({loss: 'binaryCrossentropy', optimizer: 'rmsprop', metrics: 'accuracy'});
# train/fit Model1 with base dataset
# train/fit Model2 with base dataset + additional dataset
# get difference between Model1 and Model2 with TensorFlowJs here
我希望得到 Model1 和 Model2 之间的权重差异
要获得模型的权重,可以使用 getWeights for each layer. The answer
检索两个模型的权重后,可以使用 sub 运算符找出两者之间的差异。