Keras 下面的代码不是由GPU运行的,而是我的原始代码,mnist是用GPU运行的吗?
我最初的keras.Tensorflow 2.0由GPU运行Keras 下面的代码不是由GPU运行的,而是我的原始代码,mnist是用GPU运行的吗?,keras,gpu,conv-neural-network,mnist,tf.keras,Keras,Gpu,Conv Neural Network,Mnist,Tf.keras,我最初的keras.Tensorflow 2.0由GPU运行 但我尝试运行此代码 for label in range(10): print('***** label {} *****'.format(label)) y_c = model.output[0, label] grads = keras.backend.gradients(y_c, model.input)[0] saliency = keras.backend.function([model.in
但我尝试运行此代码
for label in range(10):
print('***** label {} *****'.format(label))
y_c = model.output[0, label]
grads = keras.backend.gradients(y_c, model.input)[0]
saliency = keras.backend.function([model.input], [grads])
idx_coord = np.where(y_test == label)[0]
X = np.zeros((batch_size, 28, 28, 1))
for batch in range(batch_size):
X[batch,...,0] = x_test[idx_coord[batch]]/255
Y = np.array([[1 if label==i else 0 for i in range(10)] for _ in range(batch_size)])
for batch in tqdm.trange(batch_size):
x_input = X[batch,...,0].copy()
y_input = Y[batch].copy()
score_list = []
if isplot:
plt.figure(figsize=(30,30))
for it in range(iteration):
score = model.evaluate(x_input[np.newaxis,...,np.newaxis], y_input[np.newaxis,...], verbose=0)[1]
score_list.append(score)
#img, gradmap =get_gradcam(x_test[idx], model, idx,"conv2d_33")
gradmap = np.abs(np.squeeze(get_smoothgrad(x_input[np.newaxis,...,np.newaxis], saliency, sigma=sigma)))
if isplot:
plt.subplot(1,20,2*(it%10)+1)
plt.imshow(np.squeeze(x_input))
plt.subplot(1,20,2*(it%10)+2)
plt.imshow(np.squeeze(gradmap))
if it%10 == 9:
plt.show()
plt.figure(figsize=(30,30))
coord = np.where(gradmap == gradmap.max())
x_input[coord] = 0.
tot_score[label].append(score_list)
我不确定这批处理如何与mnist一起工作但是gpu没有使用此代码运行
你能做一个pip冻结并检查你是否安装了tensorflow gpu包吗?当我只是训练常规mnist训练时,gpu正在工作,但上面的代码没有用gpu运行