cs231n assignment1 features

features

前几个作业都是直接将图片的原始像素作为模型输入,本次作业是通过使用定向梯度直方图Histogram of Oriented Gradients (HOG)和HSV颜色空间。简单说,HOG不考虑图片的颜色信息,只捕获图片的纹理;而颜色直方图只考虑颜色,不考虑纹理。使用这两个方法一起工作,效果会更好。

Train SVM on features
learning_rates = [0.8e-7,1e-7,1.2e-7,1.4e-7]
regularization_strengths = [5e4,5.1e4]

for lr in learning_rates:
    for rs in regularization_strengths:
        svm = LinearSVM()
        loss_history = svm.train(X_train_feats,y_train,learning_rate=lr,reg=rs,num_iters=1000)
        train_pred = svm.predict(X_train_feats)
        train_acc = np.mean(train_pred == y_train)
        val_pred = svm.predict(X_val_feats)
        val_acc = np.mean(val_pred == y_val)
        if val_acc > best_val:
            best_val = val_acc
            best_svm = svm
        results[(lr,rs)] = (train_acc,val_acc)
        plt.subplot()
        plt.plot(loss_history, label='loss')
        plt.legend()
        plt.show()
pass

准确率不是很高,我只达到了:42。3%

测试数据集的准确率为:41.4%

分类展示:
在这里插入图片描述


Neural Network on image features
自己选择了一些超参,画图看出梯度下降的效果非常棒,但是准确率小的可怜。只好参考别人的博客,准确率提高至57.7%,测试数据集准确率为57.4%。

代码:

reg = [1e-3]
learing_rate = [5e-1]
best_acc = 0.4
for r in reg:
    for lr in learing_rate:
        # Train the network
        stats = net.train(X_train_feats, y_train, X_val_feats, y_val,
                    num_iters=1000, batch_size=200,
                    learning_rate=lr, learning_rate_decay=0.95,
                    reg=r, verbose=False)
        # Predict on the validation set
        val_acc = (net.predict(X_val_feats) == y_val).mean()
        print('reg:%f,learning_rate:%f'%(r,lr))
        print('Validation accuracy: ', val_acc)
        if (val_acc > best_acc):
            best_acc = val_acc
            best_net = net

        plt.subplot(2, 1, 1)
        plt.plot(stats['loss_history'])
        plt.title('Loss history')
        plt.xlabel('Iteration')
        plt.ylabel('Loss')

        plt.subplot(2, 1, 2)
        plt.plot(stats['train_acc_history'], label='train')
        plt.plot(stats['val_acc_history'], label='val')
        plt.title('Classification accuracy history')
        plt.xlabel('Epoch')
        plt.ylabel('Classification accuracy')
        plt.legend()
        plt.show()
pass

Inline Question

Inline question 1:

Describe the misclassification results that you see. Do they make sense?

YourAnswer:\color{blue}{\textit Your Answer:}
虽然存在分类错误的图片,但是还是有一定道理的。卡车和汽车形态较像、猫和狗也很像,因此被识别错误很正常。但是还有很多差别很大的图片也被分类错误,从图中可以看出卡车里面居然有狗和🦌。。。emmmmm

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章