我正试图将两种经过预先训练的角膜模型移植到议会联盟的机器中。我成功地使用IPUstrategy.scope加载并运行了它们,但是我不知道我这样做是否正确。我有我的预培训模型的.h5文件格式。我用这种方式装载它们:
def first_model():
model = tf.keras.models.load_model("./model1.h5")
return model 在搜索您的ipu.keras.models.py文件后,我找不到任何加载方法来加载经过预先训练的模型,这就是我使用tf.keras.models.load_model()的原因。
然后,我使用以下代码运行:
cfg=ipu.utils.create_ipu_config()
cfg=ipu.utils.auto_select_ipus(cfg, 1)
ipu.utils.configure_ipu_system(cfg)
ipu.utils.move_variable_initialization_to_cpu()
strategy = ipu.ipu_strategy.IPUStrategy()
with strategy.scope():
model = first_model()
print('compile attempt\n')
model.compile("sgd", "categorical_crossentropy", metrics=["accuracy"])
print('compilation completed\n')
print('running attempt\n')
res = model.predict(input_img)[0]
print('run completed\n')您可以在这里看到输出:链接
因此,我有一些困难,以了解该系统如何和是否正常运作。基本上,model.compile不会编译我的模型,但是当我使用model.predict时,系统首先编译,然后运行。为什么会发生这种事?有没有其他方法可以在议会联盟的芯片上运行经过预先训练的角膜模型?
我的另一个问题是,是否有可能在ipu.keras.model中加载一个预先训练过的keras模型,然后使用模型. for /评估来进一步训练和评估它,然后将它保存起来供将来使用?
最后一个问题是关于图表的编译部分。是否有一种方法可以避免每次在不同的model.predict()中使用strategy.scope()来重新编译图形?
我用的是张量2.1.2轮
谢谢您抽时间见我
发布于 2021-04-27 10:24:32
为了添加一些上下文,Graphcore TensorFlow轮毂包含一个用于议会联盟的Keras端口,可作为tensorflow.python.ipu.keras使用。您可以在此链接上访问议会联盟Keras的API文档。这个模块包含议会联盟特定的TensorFlow Keras类 Model和Sequential的优化替换,以及更高性能、多议会联盟类(如PipelineModel和PipelineSequential )。
根据你的具体问题,当你提到目前还没有议会联盟特定的方法来加载经过预先训练的Keras模型时,你是正确的。我鼓励您,因为您似乎可以访问IPU,向Graphcore提供支持。在这样做时,请附加您的预先培训的Keras模型model1.h5和一个独立的复制您的代码。
将主题切换到重新编译问题:使用可执行缓存可以防止重新编译,可以使用环境变量TF_POPLAR_FLAGS='--executable_cache_path=./cache'进行设置。我还建议查看以下资源:
https://stackoverflow.com/questions/67229134
复制相似问题