美好的一天。我有一个奇怪的错误。这段代码是完全可行的(如果有文件),这意味着我应该重新安装一些程序。
我现在在Anaconda上使用python 3.6.6,以tensorflow 1.9.0作为后端的keras工作。 Windows7。GPU是nvidia GTX 760 2 GB。 我已经尝试过重新安装驱动程序(使用“全新安装”检查),CUDA 9.0,甚至删除带有文件夹的Anaconda并重新安装。
错误
runfile('D:/AnacondaProjects/nt2_keras/kerasAECD.py', wdir ='D:/ AnacondaProjects / nt2_keras')使用TensorFlow后端。培养 对49000个样本进行验证,对3000个样本进行验证时期1/1追溯(大多数 最近通话结束):
文件“”,第1行,在 runfile('D:/AnacondaProjects/nt2_keras/kerasAECD.py',wdir ='D:/ AnacondaProjects / nt2_keras')
文件 “ D:\ ProgramData \ Anaconda3 \ envs \ tensorflow \ lib \ site-packages \ spyder_kernels \ customize \ spydercustomize.py”, 运行文件中的第668行 execfile(文件名,命名空间)
文件 “ D:\ ProgramData \ Anaconda3 \ envs \ tensorflow \ lib \ site-packages \ spyder_kernels \ customize \ spydercustomize.py”, execfile中的第108行 exec(compile(f.read(),文件名,'exec'),命名空间)
文件“ D:/AnacondaProjects/nt2_keras/kerasAECD.py”,第77行,在 validation_data =(eval_in,eval_in))
文件 “ D:\ ProgramData \ Anaconda3 \ envs \ tensorflow \ lib \ site-packages \ keras \ engine \ training.py”, 1037行,适合 validate_steps = validation_steps)
文件 “ D:\ ProgramData \ Anaconda3 \ envs \ tensorflow \ lib \ site-packages \ keras \ engine \ training_arrays.py”, 在fit_loop中的第199行 outs = f(ins_batch)
文件 “ D:\ ProgramData \ Anaconda3 \ envs \ tensorflow \ lib \ site-packages \ keras \ backend \ tensorflow_backend.py”, 第2666行,在致电中 返回self._call(inputs)
文件 “ D:\ ProgramData \ Anaconda3 \ envs \ tensorflow \ lib \ site-packages \ keras \ backend \ tensorflow_backend.py”, _call中的第2636行 提取= self._callable_fn(* array_vals)
文件 “ D:\ ProgramData \ Anaconda3 \ envs \ tensorflow \ lib \ site-packages \ tensorflow \ python \ client \ session.py”, 第1454行,在致电中 self._session._session,self._handle,参数,状态,无)
文件 “ D:\ ProgramData \ Anaconda3 \ envs \ tensorflow \ lib \ site-packages \ tensorflow \ python \ framework \ errors_impl.py”, 第519行,位于退出中 c_api.TF_GetCode(self.status.status))
内部错误:CUB分段减少错误错误的设备功能
[[节点:loss / conv2d_6_loss / Mean_1 =平均值[T = DT_FLOAT,Tidx = DT_INT32, _class = [“ loc:@ training / Adam / gradients / loss / conv2d_6_loss / Mean_1_grad / truediv”], keep_dims = false, _device =“ / job:localhost / replica:0 / task:0 / device:GPU:0”](loss / conv2d_6_loss / Mean, 培训/亚当/梯度/损失/ conv2d_6_loss /平均值_1_grad / mod)]]
[[节点:损失/ mul / _123 = _Recvclient_terminated = false, recv_device =“ / job:localhost /副本:0 / task:0 / device:CPU:0”, send_device =“ / job:localhost /副本:0 / task:0 / device:GPU:0”, send_device_incarnation = 1,tensor_name =“ edge_719_loss / mul”, tensor_type = DT_FLOAT, _device =“ / job:localhost /副本:0 /任务:0 /设备:CPU:0”]]
我的代码,输入的是屏幕上的黑白图片,调整大小并保存在文件中。您可以创建随机的numpy数组,这无关紧要。只是想再次使用NN,而无需重新安装Windows。
import tensorflow as tf
import numpy as np
import os
from random import shuffle
from keras import backend as K
from keras.models import Model, load_model
from keras.layers import Input, Dense, Activation, Conv2D
from keras.layers import MaxPooling2D, UpSampling2D
from keras.optimizers import Adam
tf.reset_default_graph()
filename_ev = 'training_data_eval.npy'
filename = 'training_data_norm.npy'
filename1 = 'training_data_norm1.npy'
filename2 = 'training_data_norm2.npy'
filename3 = 'training_data_norm3.npy'
if os.path.isfile(filename):
train_data = np.load(filename)
train_data1 = np.load(filename1)
train_data2 = np.load(filename2)
train_data3 = np.load(filename3)
eval_data = np.load(filename_ev)
tr_in = []
ev_in = []
for data in train_data:
tr_in.append(data[0])
for data in train_data1:
tr_in.append(data[0])
for data in train_data2:
tr_in.append(data[0])
for data in train_data3:
tr_in.append(data[0])
for data in eval_data:
ev_in.append(data[0])
train_in = np.array(tr_in)
shuffle(train_in)
eval_in = np.array(ev_in)
train_in = train_in.reshape([-1,44,32,1])
eval_in = eval_in.reshape([-1,44,32,1])
# Building the encoder
input_img = Input(shape=(44,32,1))
x = Conv2D(32, 3, activation = 'relu', padding = 'same')(input_img)
x = MaxPooling2D(2, padding = 'same')(x)
x = Conv2D(16, 3, activation='relu', padding='same')(x)
x = MaxPooling2D(2, padding='same')(x)
#x = Conv2D(4, 3, activation='relu', padding='same')(x)
#encoded = MaxPooling2D(2, padding='same')(x)
encoded = Conv2D(4, 3, activation='relu', padding='same')(x)
#x = Conv2D(4, 3, activation='relu', padding='same')(x)
x = UpSampling2D(2)(x)
x = Conv2D(16, 3, activation='relu', padding='same')(x)
x = UpSampling2D(2)(x)
x = Conv2D(32, 3, activation='relu', padding='same')(x)
decoded = Conv2D(1, 3, activation = 'sigmoid', padding = 'same')(x)
autoencoder = Model(input_img, decoded)
optim = Adam(lr = 0.0005)
autoencoder.compile(optimizer = optim, loss = 'mean_squared_error')
#autoencoder = load_model('kerasAECD2')
autoencoder.fit(train_in, train_in,
epochs = 1,
batch_size = 512,
shuffle = True,
validation_data = (eval_in,eval_in))
autoencoder.save('kerasAECD2')
allin = []
tmp = autoencoder.predict(eval_in)
for data in tmp:
img = data.reshape([44,32])
allin.append(img)
np.save('kaeCD.npy',allin)
del autoencoder
K.clear_session()
但是最简单的代码正在工作:
import tensorflow as tf
tf.reset_default_graph()
# Creates a graph.
with tf.device('/gpu:0'):
a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a')
b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name='b')
c = tf.matmul(a, b)
# Creates a session with log_device_placement set to True.
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))
# Runs the op.
print(sess.run(c))
输出为[[22,28],[49,64]]
我通过重启重新安装Anaconda解决了问题。 WTF?我已经重新安装了它而没有任何更改。好。 关闭问题?