验证文件是否存在于Tensorflow流中。使用tf.gfile.Exists和字符串Tensor作为输入

时间:2018-09-13 19:17:31

标签: python tensorflow

使用Tensorflow我试图在使用tf.read_file(filename)读取文件之前验证文件是否存在。不幸的是,在设置管道的方式中,我正在使用tf命令动态生成文件名字符串。我使用tf.string_join生成了文件名字符串,然后想通过调用tf.gfile.Exists来验证文件是否存在。不幸的是,tf.gfile.Exists仅接受字符串,而不接受张量。如何验证Tensorflow中是否存在文件?我可以在运行时评估张量吗?还有其他解决方法或正确的方法吗?

1 个答案:

答案 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