Exemplo n.º 1
0
correct_prediction = tf.equal(predictions["classes"], tf.argmax(y, axis=1))
accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))

TP = tf.metrics.true_positives(labels=tf.argmax(y, axis=1), predictions=predictions["classes"])
FP = tf.metrics.false_positives(labels=tf.argmax(y, axis=1), predictions=predictions["classes"])
TN = tf.metrics.true_negatives(labels=tf.argmax(y, axis=1), predictions=predictions["classes"])
FN = tf.metrics.false_negatives(labels=tf.argmax(y, axis=1), predictions=predictions["classes"])
recall = tf.metrics.recall(labels=tf.argmax(y, axis=1), predictions=predictions["classes"])
tf_accuracy = tf.metrics.accuracy(labels=tf.argmax(y, axis=1), predictions=predictions["classes"])

# ------------------------------------------------------------------------------------------


# ------------------------------ 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))
Exemplo n.º 2
0
                                  predictions=predictions["classes"])

# ------------------------------------------------------------------------------------------

# ------------------------------ train model ------------------------------
print("\n" + "=" * 50 + "Benign Trainging" + "=" * 50)

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
                                  })
Exemplo n.º 3
0
print("\n" + "=" * 50 + "Benign Trainging" + "=" * 50)

# config = tf.ConfigProto()
# config.gpu_options.allow_growth = True
#
# sess = tf.Session(config=config)

##### 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
                                  })