python - 使用 tf.gfile.GFile 时 Python 退出
问题描述
当我尝试使用经过训练的模型时,我曾经使用tf.gfile.GFile
以下代码部分来阅读我的标签:
import sys
import os
import matplotlib
import numpy as np
import matplotlib.pyplot as plt
import copy
import cv2
# Disable tensorflow compilation warnings
os.environ['TF_CPP_MIN_LOG_LEVEL']='2'
import tensorflow as tf
def predict(image_data):
predictions = sess.run(softmax_tensor, \
{'DecodeJpeg/contents:0': image_data})
# Sort to show labels of first prediction in order of confidence
top_k = predictions[0].argsort()[-len(predictions[0]):][::-1]
max_score = 0.0
res = ''
for node_id in top_k:
human_string = label_lines[node_id]
score = predictions[0][node_id]
if score > max_score:
max_score = score
res = human_string
return res, max_score
# Loads label file, strips off carriage return
label_lines = [line.rstrip() for line
in tf.gfile.GFile("logs/output_labels.txt")]
问题在于这一行:
label_lines = [line.rstrip() for line in tf.gfile.GFile("logs/output_labels.txt")]
Python进程退出
我只收到以下警告:
WARNING:tensorflow:From classify_webcam.py:35: The name tf.gfile.GFile is deprecated. Please use tf.io.gfile.GFile instead.
是什么导致了这个问题?
注意我正在使用tensorflow 1.14.0
解决方案
检查我的logs
文件夹后,我发现output_labels.txt
没有生成,所以在重新训练我的模型并生成标签文件后,tf.io.gfile.GFile
工作正常!
推荐阅读
- r - 如何制作具有多个条件的 ifelse 语句
- javascript - 是否可以使用 React 将 Spring-animation 应用于 img src 更改?
- javascript - 车把/节点更改日期格式
- c# - 将所选数据保存在 cookie 中失败
- typescript - 在 Typescript 中创建一个元组数组
- amazon-redshift - 更改架构名称,然后再次更改回来
- python - 使用 Python 更新 JSON 文件中的值
- javascript - Angular 7 中连接性的布尔测试
- python - 多类 Keras 感知器分类器将所有内容分类为一个类
- c# - 如何使解决方案引用不同的形式?