我目前正在开展单图像超分辨率的工作,并已经设法冻结现有的检查点文件并将其转换为TensorFlow Lite。但是,使用.tflite文件进行推理时,上采样一个图像所需的时间至少比使用.ckpt文件还原模型时多4倍。
使用.ckpt文件进行推理是使用session.run()完成的,而使用.tflite文件进行推理是使用interpreter.invoke()完成的。两个操作都在运行于典型个人电脑的Ubuntu 18 VM中进行。
我为了查找更多问题的信息,运行了top
命令以在单独的终端窗口中查看CPU利用率。使用.ckpt文件时,利用率达到270%,而使用.tflite文件时则保持在约100%左右。
interpreter.set_tensor(input_details[0]['index'], input_image_reshaped)
interpreter.set_tensor(input_details[1]['index'], input_bicubic_image_reshaped)
start = time.time()
interpreter.invoke()
end = time.time()
对比
y = self.sess.run(self.y_, feed_dict={self.x: image.reshape(1, image.shape[0], image.shape[1], ch), self.x2: bicubic_image.reshape(1, self.scale * image.shape[0], self.scale * image.shape[1], ch), self.dropout: 1.0, self.is_training: 0})
有一种假设是tensorflow lite没有配置多线程,另一种假设是tensorflow lite针对ARM处理器进行了优化(而不是我的电脑上运行的英特尔处理器),因此速度较慢。然而,我无法确定,也不知道如何追踪问题的根源 - 希望有人能更了解这个问题?