я запускаю coed с rtx2080, используя докер.
Как только я вызываю sess.run (train_step, feed_dick = {}), я получаю «Процесс завершен с кодом выхода 139 (прерван сигналом 11: SIGSEGV)». Но если я запускаю его с процессором, он работает хорошо.
я понятия не имею, что случилось.
Использование бэкэнда TensorFlow.
2018-11-18 13: 19: 12.025412: I
tenorflow / core / platform / cpu_feature_guard.cc: 141] Ваш процессор поддерживает
инструкции, что этот двоичный файл TensorFlow не был скомпилирован для использования: AVX2
FMA 2018-11-18 13: 19: 12.132999: I
tenorflow / stream_executor / cuda / cuda_gpu_executor.cc: 964] успешно
Чтение узла NUMA из SysFS имело отрицательное значение (-1), но должно быть
по крайней мере один узел NUMA, поэтому возвращается ноль узла NUMA 2018-11-18
13: 19: 12.133566: I
tenorflow / core / common_runtime / gpu / gpu_device.cc: 1432] Найдено устройство 0
со свойствами: имя: GeForce RTX 2080 мажор: 7 минор: 5
MemoryClockRate (GHz): 1,8 pciBusID: 0000: 06: 00.0 всего Память: 7,76 ГБ
freeMemory: 7,46 ГБ 2018-11-18 13: 19: 12,133584: I
tenorflow / core / common_runtime / gpu / gpu_device.cc: 1511] Добавление видимого
Устройства GPU: 0 2018-11-18 13: 19: 12.394726: I
tenorflow / core / common_runtime / gpu / gpu_device.cc: 982] Устройство
соединить StreamExecutor с прочностью 1 ребра матрицы: 2018-11-18
13: 19: 12.394763: I
tenorflow / core / common_runtime / gpu / gpu_device.cc: 988] 0
2018-11-18 13: 19: 12.394770: I
tenorflow / core / common_runtime / gpu / gpu_device.cc: 1001] 0: N
2018-11-18 13: 19: 12.394963: I
tenorflow / core / common_runtime / gpu / gpu_device.cc: 1115] Создано
Устройство TensorFlow (/ job: localhost / replica: 0 / task: 0 / device: GPU: 0 with
7172 МБ памяти) -> физический графический процессор (устройство: 0, название: GeForce RTX 2080,
идентификатор шины pci: 0000: 06: 00.0, вычислительная мощность: 7,5)
import tensorflow as tf
import numpy as np
import pandas as pd
from tensorflow.contrib.framework import arg_scope
from keras.layers import Dense, Activation
import pickle
from tensorflow.contrib.layers import batch_norm, flatten
train_data = {b'data': [], b'labels': []}
# 加载训练数据
for i in range(5):
with open("data/cifar-10/data_batch_" + str(i + 1), mode='rb') as file:
data = pickle.load(file, encoding='bytes')
train_data[b'data'] += list(data[b'data'])
train_data[b'labels'] += data[b'labels']
# 加载测试数据
with open("data/cifar-10/test_batch", mode='rb') as file:
test_data = pickle.load(file, encoding='bytes')
# 定义一些变量
NUM_LABLES = 10 # 分类结果为10类
BATCH_SIZE = 64 # 每次训练batch数
sess = tf.InteractiveSession()
# 权重初始化
def weight_variable(shape):
initial = tf.truncated_normal(shape, stddev=2 / shape[0] / shape[1] / shape[2])
# initial = tf.truncated_normal(shape, stddev=0.01)
return tf.Variable(initial)
# 卷积层偏置初始化为常数0.1
def bias_variable(shape):
initial = tf.constant(0.1, shape=shape)
return tf.Variable(initial)
# 定义卷积操作,卷积步长为1. padding = 'SAME' 表示全0填充
def conv2d(x, W):
return tf.nn.conv2d(x, W, strides=[1, 1, 1, 1], padding='SAME')
# 定义最大池化操作,尺寸为2,步长为2,全0填充
def max_pool_2x2(x):
return tf.nn.max_pool(x, ksize=[1, 2, 2, 1], strides=[1, 2, 2, 1], padding='SAME')
# 对输入进行占位操作,输入为BATCH*3072向量,输出为BATCH*10向量
x = tf.placeholder(tf.float32, [None, 3072])
y_ = tf.placeholder(tf.float32, [None, NUM_LABLES])
# 对输入进行reshape,转换成3*32*32格式
x_image = tf.reshape(x, [-1, 3, 32, 32])
# 转置操作,转换成滤波器做卷积所需格式:32*32*3,32*32为其二维卷积操作维度
x_image = tf.transpose(x_image, [0, 2, 3, 1])
# 第一层卷积,滤波器参数3*3*3, 32个
#bn_layer1 = Batch_Normalization(x_image, istraining, "bn1")
W_conv1 = weight_variable([3, 3, 3, 32])
b_conv1 = bias_variable([32])
h_conv1 = conv2d(x_image, W_conv1) + b_conv1
#h_conv1 = tf.layers.dropout(inputs=h_conv1, rate=droprate, training=istraining)
h_relu1 = tf.nn.relu(h_conv1) # 卷积
h_pool1 = max_pool_2x2(h_relu1) # 池化
h_pool4 = tf.reshape(h_pool1,[-1,16*16*32])
bn_layer5_flat = tf.layers.dense(inputs=h_pool4, units=10, name='linear')
cross_entropy = tf.losses.softmax_cross_entropy(onehot_labels=y_, logits=bn_layer5_flat,
reduction=tf.losses.Reduction.MEAN)
train_step = tf.train.AdamOptimizer(1e-4).minimize(cross_entropy)
correct_prediction = tf.equal(tf.argmax(bn_layer5_flat, 1), tf.argmax(y_, 1))
accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
sess.run(tf.global_variables_initializer())
x_train = np.array(train_data[b'data']) / 255
y_train = np.array(pd.get_dummies(train_data[b'labels']))
x_test = test_data[b'data'] / 255
y_test = np.array(pd.get_dummies(test_data[b'labels']))
eplr = 1e-4;
for i in range(20000):
if i == 20000 * 0.5 or i == 20000 * 0.75:
eplr = eplr / 10
start = i * BATCH_SIZE % (50000 - BATCH_SIZE)
sess.run(train_step,feed_dict={x: x_train[start: start + BATCH_SIZE],
y_: y_train[start: start + BATCH_SIZE],
})
if i % 100 == 0:
train_accuracy = accuracy.eval(feed_dict={x: x_test[0: 200],
y_: y_test[0: 200]
})
loss_value = cross_entropy.eval(feed_dict={x: x_train[start: start + BATCH_SIZE],
y_: y_train[start: start + BATCH_SIZE]
})
print("step %d, trainning accuracy, %g loss %g" % (i, train_accuracy, loss_value))
test_accuracy = accuracy.eval(feed_dict={x: x_test, y_: y_test})
print("test accuracy %g" % test_accuracy)