如果我尝试使用
导入已保存的TensorFlow图表定义import tensorflow as tf
from tensorflow.python.platform import gfile
with gfile.FastGFile(FLAGS.model_save_dir.format(log_id) + '/graph.pb', 'rb') as f:
graph_def = tf.GraphDef()
graph_def.ParseFromString(f.read())
x, y, y_ = tf.import_graph_def(graph_def,
return_elements=['data/inputs',
'output/network_activation',
'data/correct_outputs'],
name='')
返回的值不是预期的Tensor
,而是其他内容:例如,将x
作为
Tensor("data/inputs:0", shape=(?, 784), dtype=float32)
我得到了
name: "data/inputs_1"
op: "Placeholder"
attr {
key: "dtype"
value {
type: DT_FLOAT
}
}
attr {
key: "shape"
value {
shape {
}
}
}
也就是说,而不是获得预期的张量x
,x.op
。这让我感到困惑,因为documentation似乎说我应该得到一个Tensor
(虽然有一堆或那里很难理解)。
如何让tf.import_graph_def
返回我可以使用的特定Tensor
(例如,在提供加载的模型或运行分析时)?
答案 0 :(得分:4)
名称@echo off
title Shall We Play a Game?
color 0b
set /a tries=3
set password=Joshua
:top
echo %tries% Tries Remaining
set /p pass=Password:
if %pass%==%password% (
goto correct
)
set /a tries=%tries -1
if %tries%==0 (
goto penalty
)
cls
goto top
:penalty
echo CONNECTION TERMINATED
pause
exit
:correct
goto greeting
:greeting
echo Shall we play a game?
echo y/n
set input=
if %input%=y goto y
if %input%=n goto n
:y
echo How about
echo Chess
echo Tic-Tac-Toe
echo Snake
echo Global Thermonuclear War
if %opt%==Chess goto Chess
if %opt%==Tic-Tac-Toe goto TicTacToe
if %opt%==Snake goto Snake
if %opt%==Global Thermonuclear War goto Global Thermonuclear War
:n
echo Thats too bad! Maybe we should play some other day!
pause
exit
:chess
:tictactoe
echo Are you sure?
echo y/n
set response=
if %response%==y goto tictactoe1
if %response%==n goto tictactoe2
:tictactoe1
echo Go Back?
echo y/n
set feedback=
if %feedback%==y goto greeting
if %feedback%==n goto tictactoe2
:tictactoe2
echo testing
goto tictactoe2
,'data/inputs'
和'output/network_activation'
实际上是操作名称。要使'data/correct_outputs'
返回tf.import_graph_def()
个对象,您应该将输出索引附加到操作名称,对于单输出操作通常为tf.Tensor
:
':0'