我试图使用keras找到自动编码器单元中隐藏层的激活,模型运行正常但是当我试图找出隐藏的激活时,它会抛出与CUDA相关的错误,然后内核死掉并重新启动。
Keras版本2.0.8
%matplotlib inline
from PIL import Image, ImageFile
from matplotlib import pyplot as plt
from sklearn import metrics
import numpy as np
from keras.models import Sequential
from keras.layers import Dense
# Fit regression DNN model.
print("Creating/Training neural network")
# this is your initial model
model = Sequential()
model.add(Dense(400, input_dim=x.shape[1], activation='relu'))
model.add(Dense(200, activation='relu'))
model.add(Dense(x.shape[1])) # Multiple output neurons
model.compile(loss='mean_squared_error', optimizer='adam')
model.fit(x,x,verbose=0,epochs=100)
print("Score neural network")
pred = model.predict(x)
获取隐藏图层激活的代码
import keras.backend as K
def get_activations(model, layer, X_batch):
get_activations = K.function([model.layers[0].input, K.learning_phase()], [model.layers[layer].output])
activations = get_activations([X_batch,0])
return activations
my_featuremaps =get_activations(model, 1, x)
conda提示符抛出错误
2018-01-29 17:54:21.660022: I C:\tf_jenkins\home\workspace\rel-win\M\windows-gpu\PY\36\tensorflow\core\platform\cpu_feature_guard.cc:137] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX
2018-01-29 17:54:22.275065: I C:\tf_jenkins\home\workspace\rel-win\M\windows-gpu\PY\36\tensorflow\core\common_runtime\gpu\gpu_device.cc:1030] Found device 0 with properties:
name: GeForce GT 740M major: 3 minor: 5 memoryClockRate(GHz): 1.0325
pciBusID: 0000:01:00.0
totalMemory: 2.00GiB freeMemory: 1.66GiB
2018-01-29 17:54:22.275240: I C:\tf_jenkins\home\workspace\rel-win\M\windows-gpu\PY\36\tensorflow\core\common_runtime\gpu\gpu_device.cc:1120] Creating TensorFlow device (/device:GPU:0) -> (device: 0, name: GeForce GT 740M, pci bus id: 0000:01:00.0, compute capability: 3.5)
2018-01-29 17:54:29.032758: I C:\tf_jenkins\home\workspace\rel-win\M\windows-gpu\PY\36\tensorflow\core\common_runtime\gpu\gpu_device.cc:1120] Creating TensorFlow device (/device:GPU:0) -> (device: 0, name: GeForce GT 740M, pci bus id: 0000:01:00.0, compute capability: 3.5)
2018-01-29 17:57:54.356314: E C:\tf_jenkins\home\workspace\rel-win\M\windows-gpu\PY\36\tensorflow\stream_executor\cuda\cuda_driver.cc:1228] failed to enqueue async memcpy from host to device: CUDA_ERROR_LAUNCH_FAILED; GPU dst: 00000005014FFC00; host src: 000001A08A1AF040; size: 3136000=0x2fda00
2018-01-29 17:57:54.356669: E C:\tf_jenkins\home\workspace\rel-win\M\windows-gpu\PY\36\tensorflow\stream_executor\stream.cc:306] Error recording event in stream: error recording CUDA event on stream 000001A0654E1060: CUDA_ERROR_LAUNCH_FAILED; not marking stream as bad, as the Event object may be at fault. Monitor for further errors.
2018-01-29 17:57:54.357151: E C:\tf_jenkins\home\workspace\rel-win\M\windows-gpu\PY\36\tensorflow\stream_executor\cuda\cuda_event.cc:49] Error polling for event status: failed to query event: CUDA_ERROR_LAUNCH_FAILED