如何解决“训练数据的顺序影响准确性”?

时间:2019-11-04 08:47:47

标签: python tensorflow

当我使用Cat&Dog数据集训练我的CNN模型时,准确性受数据集顺序的影响。  精度计数器从输入[0]到输入[3000]增加,然后对于输入[3000]〜输入[6000]很少增加。  这意味着该模型对训练集中的每只猫进行分类,而很少对某些狗进行分类。  尽管训练是基于混合数据,但它确实发生了。  我不知道怎么了。

#Random Order
ROB = [] ; batch_size = 30 ; Total_size = 6000/batch_size
for i in range(int(Total_size)):
    x = rd.randint(0,Total_size-1)
    while x in ROB:
        x = rd.randint(0,Total_size-1)
    ROB.append(x)
#Train
for epoch in range(5):

    for i in ROB:
        start = ((i+1) * batch_size) - batch_size
        end = ((i+1) * batch_size)
        batch_xs = ip[start:end]
        batch_ys = op[start:end]
        feed_dict = {X: batch_xs, Y:batch_ys, keep_prob:0.8}
        l, _ = sess.run([loss,optimizer], feed_dict= feed_dict)
    print('Epoch:{} - Loss:{}'.format(epoch,l))
    if (epoch+1)%1 ==0:
        correct_prediction = tf.equal(tf.argmax(logits,1),tf.argmax(Y,1))
        accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
        count = 0
        for j in range(6000):
            count += sess.run(accuracy, feed_dict={X:[ip[j]], Y:[op[j]], keep_prob:1.0})
            if sess.run(accuracy, feed_dict={X:[ip[j]], Y:[op[j]], keep_prob:1.0})==1:
                print(j)
        print(count)

0 个答案:

没有答案