小编Jac*_*cob的帖子

如何使用tensorflow实时分类图像?

我正在尝试使用覆盆子pi相机捕捉图像并将图像实时分为三类.我所做的是使用下面的代码.它可以在第一次迭代中预测.问题是它显示我在第二次迭代后耗尽了内存.有没有什么办法解决这一问题?

import numpy as np
import tensorflow as tf
import argparse
import os
import sys

def create_graph(model_file):
    """Creates a graph from saved GraphDef file and returns a saver."""
    # Creates graph from saved graph_def.pb.
    with tf.gfile.FastGFile(model_file, 'rb') as f:
        graph_def = tf.GraphDef()
        graph_def.ParseFromString(f.read())
        _ = tf.import_graph_def(graph_def, name='')


def run_inference(images, out_file, labels, model_file, k=5):

    # Creates graph from saved GraphDef.
    create_graph(model_file)

    if out_file:
        out_file = open(out_file, 'wb', 1)

    with tf.Session() as sess:
        softmax_tensor = sess.graph.get_tensor_by_name('final_result:0')
        for img in images:
            if not …
Run Code Online (Sandbox Code Playgroud)

python-2.7 deep-learning tensorflow raspberry-pi3

3
推荐指数
1
解决办法
1763
查看次数