Tensorflow错误无法创建目录 [英] Tensorflow error failed to create directory

查看:1130
本文介绍了Tensorflow错误无法创建目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个深度学习程序,并试图训练数据.我已经开始使用张量板,但是在创建文件时遇到了一个错误,说程序无法创建目录,并且没有这样的文件或目录.

I am creating a deep learning program and am trying to train the data. I have began to use the tensorboard but ran into an error in relation to the file created, saying that the program failed to create a directory, and that there is no such file or directory.

我按照senddex教程进行了python第4部分的深度学习,但是仍然有错误.

I followed sentdex tutorial for deep learning on python part 4 and still had errors.

import tensorflow as tf
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Dropout, Activation, Flatten, Conv2D, MaxPooling2D
import pickle
import time
from tensorflow.keras.datasets import cifar10
from tensorflow.keras.preprocessing.image import ImageDataGenerator
from tensorflow.keras.callbacks import TensorBoard

NAME = 'Tagged-vs-untagged-cnn-64x2-{}'.format(int(time.time()))
tensorboard = TensorBoard(log_dir='logs/{}'.format(NAME))

gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=0.333)
sess = tf.Session(config=tf.ConfigProto(gpu_options=gpu_options))


X = pickle.load(open('X.pickle', 'rb'))
y = pickle.load(open('y.pickle', 'rb'))

#data must be normalised
X = X/255.0

model = Sequential()
model.add(Conv2D(64, (3,3), input_shape = X.shape[1:]))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2,2)))

model.add(Conv2D(64, (3,3)))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2,2)))

model.add(Flatten())

model.add(Dense(1))
model.add(Activation('sigmoid'))

model.compile(loss='binary_crossentropy',
              optimizer='adam',
              metrics=['accuracy'])

model.fit(X, y, batch_size=32, epochs=10, validation_split=0.3, callbacks=[tensorboard])

我希望程序可以训练所有数据集并通过验证准确性和损失等进行跟踪.我得到以下错误: 追溯(最近一次通话): 文件"C:/用户/所有者/文档/MachineLearning/TNA/DigitalMagnets/cnn.py",第41行,在 model.fit(X,y,batch_size = 32,epochs = 10,validation_split = 0.3,callbacks = [tensorboard]) 文件"C:\ Users \ owner \ AppData \ Local \ Programs \ Python \ Python37 \ lib \ site-packages \ tensorflow \ python \ keras \ engine \ training.py",行780,适合 steps_name ='steps_per_epoch') 文件"C:\ Users \ owner \ AppData \ Local \ Programs \ Python \ Python37 \ lib \ site-packages \ tensorflow \ python \ keras \ engine \ training_arrays.py",行374,在model_iteration中 callbacks._call_batch_hook(mode,'end',batch_index,batch_logs) _call_batch_hook中的第248行,文件"C:\ Users \ owner \ AppData \ Local \ Programs \ Python \ Python37 \ lib \ site-packages \ tensorflow \ python \ keras \ callbacks.py" batch_hook(批处理,日志) 在on_train_batch_end的第531行中,文件"C:\ Users \ owner \ AppData \ Local \ Programs \ Python \ Python37 \ lib \ site-packages \ tensorflow \ python \ keras \ callbacks.py" self.on_batch_end(batch,logs = logs) 文件"C:\ Users \ owner \ AppData \ Local \ Programs \ Python \ Python37 \ lib \ site-packages \ tensorflow \ python \ keras \ callbacks_v1.py",行362,在on_batch_end中 profiler.save(self.log_dir,profiler.stop()) 保存文件``C:\ Users \ owner \ AppData \ Local \ Programs \ Python \ Python37 \ lib \ site-packages \ tensorflow \ python \ eager \ profiler.py'',行144 gfile.MakeDirs(plugin_dir) 文件``C:\ Users \ owner \ AppData \ Local \ Programs \ Python \ Python37 \ lib \ site-packages \ tensorflow \ python \ lib \ io \ file_io.py'',行438,位于recursive_create_dir中 recursive_create_dir_v2(目录名) 在recursive_create_dir_v2中的第453行中,文件"C:\ Users \ owner \ AppData \ Local \ Programs \ Python \ Python37 \ lib \ site-packages \ tensorflow \ python \ lib \ io \ file_io.py" pywrap_tensorflow.RecursivelyCreateDir(compat.as_bytes(path)) tensorflow.python.framework.errors_impl.NotFoundError:无法创建目录:logs/Tagged-vs-untagged-cnn-64x2-1563447772 \ plugins \ profile \ 2019-07-18_12-02-54;没有这样的文件或目录

I expect the program to train all the data set and trace through the validation accuracy and loss etc. I get the following error: Traceback (most recent call last): File "C:/Users/owner/Documents/MachineLearning/TNA/DigitalMagnets/cnn.py", line 41, in model.fit(X, y, batch_size=32, epochs=10, validation_split=0.3, callbacks=[tensorboard]) File "C:\Users\owner\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\keras\engine\training.py", line 780, in fit steps_name='steps_per_epoch') File "C:\Users\owner\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\keras\engine\training_arrays.py", line 374, in model_iteration callbacks._call_batch_hook(mode, 'end', batch_index, batch_logs) File "C:\Users\owner\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\keras\callbacks.py", line 248, in _call_batch_hook batch_hook(batch, logs) File "C:\Users\owner\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\keras\callbacks.py", line 531, in on_train_batch_end self.on_batch_end(batch, logs=logs) File "C:\Users\owner\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\keras\callbacks_v1.py", line 362, in on_batch_end profiler.save(self.log_dir, profiler.stop()) File "C:\Users\owner\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\eager\profiler.py", line 144, in save gfile.MakeDirs(plugin_dir) File "C:\Users\owner\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\lib\io\file_io.py", line 438, in recursive_create_dir recursive_create_dir_v2(dirname) File "C:\Users\owner\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\lib\io\file_io.py", line 453, in recursive_create_dir_v2 pywrap_tensorflow.RecursivelyCreateDir(compat.as_bytes(path)) tensorflow.python.framework.errors_impl.NotFoundError: Failed to create a directory: logs/Tagged-vs-untagged-cnn-64x2-1563447772\plugins\profile\2019-07-18_12-02-54; No such file or directory

推荐答案

问题不在于TensorFlow或tensorboard,而在于python,它也专门针对Windows.

The issue isn't with TensorFlow or tensorboard but rather with python, that too specifically for windows.

当前,在Unix上,SplitPath仅在正斜杠上分割;在 Windows,除非有正斜杠,否则它会以正斜杠分割 字符串中的斜线,在这种情况下,它将在反斜线处分割.这是 与_wmkdir和Tensorflow这样的平台API混淆并且不一致 将\和/都解释为有效的路径定界符.

Currently, on Unix, SplitPath splits only on forward slashes; on Windows, it splits on forward slashes unless there are no forward slashes in the string, in which case it splits on backslashes. This is confusing, and inconsistent with platform APIs like _wmkdir and Tensorflow, which interpret both \ and / as valid path delimiters.

解决方法是在log_dir中使用适合平台的路径分隔符 而不是通过os.path.join硬编码正斜杠:

The fix is to use the platform-appropriate path separators in log_dir rather than hard-coding forward slashes via os.path.join:

所以尝试一下:

tboard_log_dir = os.path.join("logs",NAME)
tensorboard = TensorBoard(log_dir = tboard_log_dir)

这应该有效

这篇关于Tensorflow错误无法创建目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆