使用Tensorflow我试图在使用tf.read_file(filename)
读取文件之前验证文件是否存在。不幸的是,在设置管道的方式中,我正在使用tf
命令动态生成文件名字符串。我使用tf.string_join
生成了文件名字符串,然后想通过调用tf.gfile.Exists
来验证文件是否存在。不幸的是,tf.gfile.Exists
仅接受字符串,而不接受张量。如何验证Tensorflow中是否存在文件?我可以在运行时评估张量吗?还有其他解决方法或正确的方法吗?
答案 0 :(得分:0)
我只是将其包装在function listbox1_Callback(hObject, eventdata, handles)
% hObject handle to listbox1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = get(hObject,'String') returns listbox1 contents as cell array
% contents{get(hObject,'Value')} returns selected item from listbox1
get(handles.figure1,'SelectionType');
if strcmp(get(handles.figure1,'SelectionType'),'open')
index_selected = get(handles.listbox1,'Value');
file_list = get(handles.listbox1,'String');
filename = file_list{index_selected}
[path,name,ext] = fileparts(filename)
fullFileName = [path, name, ext]
end
% ------------------------------------------------------------
% Read the current directory and sort the names
% ------------------------------------------------------------
function load_listbox(dir_path,handles)
cd (dir_path)
dir_struct = dir(dir_path);
[sorted_names,sorted_index] = sortrows({dir_struct.name}');
handles.file_names = sorted_names;
handles.is_dir = [dir_struct.isdir];
handles.sorted_index = sorted_index;
guidata(handles.figure1,handles)
set(handles.listbox1,'String',handles.file_names,...
'Value',1)
set(handles.text1,'String',pwd)
[1]: https://www.mathworks.com/help/matlab/creating_guis/interactive-list-box-in-a-guide-gui.html
tf.py_func