【发布时间】:2020-04-24 06:33:47
【问题描述】:
假设我有一个这样的 keras 模型:
with tf.device("/CPU"):
model = tf.keras.Sequential([
# Adds a densely-connected layer with 64 units to the model:
tf.keras.layers.Dense(64, activation='relu', input_shape=(32,)),
# Add another:
tf.keras.layers.Dense(64, activation='relu'),
# Add a softmax layer with 10 output units:
tf.keras.layers.Dense(10, activation='softmax')])
我想将此模型移至 GPU。
我试过这样做:
with tf.device("/GPU:0"):
gpu_model = tf.keras.models.clone_model(model)
但问题在于,变量名称发生了变化。例如:
第一层权重model的名字是: Got from model.layers[0].weights[0].name
'密集/内核:0'
但是第一层的权重名称gpu_model是: Got from gpu_model.layers[0].weights[0].name
'dense_3/kernel:0'
如何在保留变量名称的同时进行这种 GPU 转换?
我不想将模型保存到磁盘并再次加载
【问题讨论】:
-
是我的想法还是变量名相同?
-
@MatiasValdenegro 对不起,我复制粘贴错了。我现在编辑了它
标签: python tensorflow keras namespaces