训练稀疏模型与训练标准模型并无区别。除调整超参数外,无需执行任何其他操作。
sparse_model.compile(loss="categorical_crossentropy", optimizer="adam", metrics=["accuracy"])
sparse_model.fit(x_train, y_train, batch_size=128, epochs=15, validation_split=0.1)
sparse_model.save_weights("model_sparse_0.2", save_format="tf")
注释: 调用
save_weights
时,请使用“tf”格式来保存权重。