我正在创建一个深度学习程序,并试图训练数据。我已经开始使用张量板,但是在创建文件时遇到了一个错误,说程序无法创建目录,并且没有这样的文件或目录。
我按照senddex教程进行了python第4部分的深度学习,但是仍然有错误。
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;没有这样的文件或目录
答案 0 :(得分:0)
问题不在于TensorFlow或tensorboard,而是python,对于Windows也是如此。
当前,在Unix上,SplitPath仅在正斜杠上分割;上 Windows,除非有正斜杠,否则它会以正斜杠分割 字符串中的斜线,在这种情况下,它将在反斜线处分割。这是 与_wmkdir和Tensorflow这样的平台API混淆并且不一致 将\和/都解释为有效的路径定界符。
解决方法是在log_dir中使用适合平台的路径分隔符 而不是通过os.path.join硬编码正斜杠:
所以尝试一下:
match_parent
这应该有效