コード例 #1
0
# ------------------------------------------------------------------------------------------


# ------------------------------ train model ------------------------------

mydata_train = DataSet(data_train, label_train)
sess = tf.Session()
sess.run(tf.global_variables_initializer())
sess.run(tf.local_variables_initializer())

accuracys=[]
begin_time = datetime.now()
for i in range(train_iter):
    # print('iter:', i)
    batch = mydata_train.next_batch(128)  # 此处的batch是由[128,1600]和[128,]组成的tuple,batch[0]就是tuple
    labels = labels_transform(batch[1], classes_num)
    if (i + 1) % 20 == 0:
        train_accuracy = sess.run(accuracy, feed_dict={_X: batch[0], y: labels,
                                                       keep_prob: 1.0, batch_size: _batch_size})
        accuracys.append(train_accuracy)
        print("\nthe %dth loop,training accuracy:%f" % (i + 1, train_accuracy))
    sess.run(train_op, feed_dict={_X: batch[0], y: labels, keep_prob: 0.5, batch_size: _batch_size})
    # gc.collect()

end_time = datetime.now()
duarion = (end_time-begin_time).seconds
print('train time:',duarion)

file=open('accuracy-1DCNN12-1.txt','w')
string = str(accuracys)
コード例 #2
0
config = tf.ConfigProto()
config.gpu_options.allow_growth = True

sess = tf.Session(config=config)

sess.run(tf.global_variables_initializer())
sess.run(tf.local_variables_initializer())
_batch_size = 128
mydata_train = DataSet(data_train, label_train)
statr = time.time()

accuracys = []
begin_time = datetime.now()
for i in range(train_iter):
    batch = mydata_train.next_batch(_batch_size)
    labels = labels_transform(batch[1], class_num)
    if (i + 1) % 20 == 0:
        train_accuracy = sess.run(accuracy,
                                  feed_dict={
                                      _X: batch[0],
                                      y: labels,
                                      keep_prob: 1.0,
                                      batch_size: _batch_size
                                  })

        print("\nthe %dth loop,training accuracy:%f" % (i + 1, train_accuracy))
        accuracys.append(train_accuracy)
    sess.run(train_op,
             feed_dict={
                 _X: batch[0],
コード例 #3
0
##### errors_impl.InternalError: Failed to create session. 看看这里为什么报错

sess = tf.Session()

sess.run(tf.global_variables_initializer())
sess.run(tf.local_variables_initializer())
_batch_size = 128

mydata_train = DataSet(data_train, label_train)

accuracys = []
begin_time = datetime.now()

for i in range(train_iter):
    batch = mydata_train.next_batch(_batch_size)
    labels = labels_transform(batch[1], class_num)
    if (i + 1) % 100 == 0:
        train_accuracy = sess.run(accuracy,
                                  feed_dict={
                                      _X: batch[0],
                                      y: labels,
                                      keep_prob: 1.0,
                                      batch_size: _batch_size
                                  })
        print("\nthe %dth loop,training accuracy:%f" % (i + 1, train_accuracy))
        accuracys.append(train_accuracy)
    sess.run(train_op,
             feed_dict={
                 _X: batch[0],
                 y: labels,