美好的一天 . 我有一个奇怪的错误 . 这段代码是完全可行的(如果你有文件),嗯,这意味着,我应该重新安装一些程序 .

我现在在python 3.6.6上使用Anaconda,使用tensorflow 1.9.0作为后端 . Windows 7.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个样本Epoch 1/1 Traceback(最近一次调用最后一个):文件“”,第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行,在runfile execfile(文件名,命名空间)文件“D:\ ProgramData \ anaconda3 \ envs \ tensorflow \ lib \ site-packages \ spyder_kernels \ customize \ spydercustomize.py“,第108行,在execfile exec(compile(f.read(),filename,'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行,in fit validation_steps = validation_steps)文件“D:\ ProgramData \ Anaconda3 \ envs \ tensorflow \ lib \ site-packages \ keras \ engine \ training_arrays.py”,第199行,在fit_loop outs = f(ins_batch)文件中“ d:\ ProgramData \ Anaconda3 \ ENVS \ tensorflow \ LIB \站点包age \ keras \ backend \ tensorflow_backend.py“,第2666行,在调用中返回self._call(inputs)文件”D:\ ProgramData \ Anaconda3 \ envs \ tensorflow \ lib \ site-packages \ keras \ backend \ tensorflow_backend.py“ ,第2636行,_call fetched = self._callable_fn(* array_vals)文件“D:\ ProgramData \ Anaconda3 \ envs \ tensorflow \ lib \ site-packages \ tensorflow \ python \ client \ session.py”,第1454行,在通话中self._session._session,self._handle,args,status,None)文件“D:\ ProgramData \ Anaconda3 \ envs \ tensorflow \ lib \ site-packages \ tensorflow \ python \ framework \ errors_impl.py”,第519行, exit c_api.TF_GetCode(self.status.status))InternalError:CUB分段减少errorinvalid device function [[Node:loss / conv2d_6_loss / Mean_1 = Mean [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,training / Adam / gradients / loss / conv2d_6_loss / Mean_1_grad / mod)]] [[Node:loss / mul / _123 = _Recv client_terminated = false,recv_device =“/ job:localhost / replica:0 / task:0 / device:CPU:0”,send_device =“/ job:localhost / replica:0 / task:0 / device:GPU:0”, send_device_incarnation = 1,tensor_name =“edge_719_loss / mul”,tensor_type = DT_FLOAT,_device =“/ job:localhost / replica:0 / task:0 / device: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解决了问题 . 跆拳道?我已经重新安装了一次而没有改变 . 好 . 关闭问题?