java上使用tensorflow_使用java(spring)中嵌入的tensorflow库执行python程序不起作用...

本文档描述了在Spring框架中使用Java尝试调用包含TensorFlow库的Python脚本时遇到的问题。虽然一个简单的Python 'hello world' 脚本能够正常工作,但当尝试运行用于图像分类的TensorFlow脚本时,没有任何输出。问题在于Java程序无法正确处理包含TensorFlow的Python脚本的执行。
摘要由CSDN通过智能技术生成

首先,我在spring框架中有这个java程序试图调用一个简单的hello world python脚本 .

它工作并返回"hello world"

然后我试着运行一个嵌入了tensorflow库的python脚本,然后它什么也没有返回 . (控制台中没有打印)

python tensorflow

import tensorflow as tf import sys import os

os.environ ['TF_CPP_MIN_LOG_LEVEL'] ='2'导入张量流为tf

image_path = sys.argv [1] image_data = tf.gfile.FastGFile(image_path,'rb') . read()

label_lines = [line.rstrip()for tf.gfile.GFile中的行(“logs / trained_labels.txt”)]

用tf.gfile.FastGFile(“logs / trained_graph.pb”,'rb')作为f:graph_def = tf.GraphDef()graph_def.ParseFromString(f.read())_ = tf.import_graph_def(graph_def,name =' “)

使用tf.Session()作为sess:

softmax_tensor = sess.graph.get_tensor_by_name('final_result:0')

predictions = sess.run(softmax_tensor, \

{'DecodeJpeg/content

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值