• CS231n课程笔记:Leture2 Image Classification


     Memorize all data and labels

    1. def train(images, label):
    2. return model

    Predict the label of the most similar training image

    1. def predict(mdoel, test_images):
    2. return test_labels

    L1 distance:

    L2 distance: 

     

    codes for Nearest Neighbor classifier

    1. import numpy as np
    2. class NearestNeighbor:
    3. def __init__(self):
    4. pass
    5. def train(self, X, y):
    6. self.Xtr = X
    7. self.ytr = y
    8. def predict(self, x):
    9. num_test = X.shape[0]
    10. Ypred = np.zeros(num_test, dtype = self.ytr.dtype)
    11. for i in xrange(num_test):
    12. distances = np.sum(np.abs(self.Xtr - X[i, :]), axis = 1)
    13. min_index = np.argmin(distances)
    14. Ypred[i] = self.ytr[min_index]
    15. return Ypred

    Q:with N examples how fast are training and prediction

    A: Train O(1) predictO(N)(要和数据集中的每一个去比较)

     

     

     在训练集中选择不同的超参数来训练我们的算法  在验证集上进行评估 在验证集上表现最好的超参数集 

    cross validation

    KNN的缺点 

    Very slow at test time

    Distance metrics on pixels are not informative

    Curse of dimensionality

    所以什么是一个比较好测量图像之间距离的方法

    Linear Classification

    总结我们对训练数据的知识 and stick all that knowledge into W(PARAMENTERS)

    然后在测试的时候 我们不再需要训练数据 只需要这些参数w

    如果我们的图像size 是 32*32*3 然后我们把它展开成3072*1的向量 如果我们想要得到10*1的class scores 我们就需要乘以10*3072的参数矩阵 有时候我们也会加上一个10*1 的bias

    举例说明

     所以 linear classification 可以看作是 template matching approach 矩阵中的每一行对应图像的某个板块

    如果我们用这种方法看待linear classification 我们实际可以获取该权重矩阵的行 并将他们分解回图像 and visualize those templates as images

    我们现在可以可视化与cifar-10中十个类别中的每一个相对应的学习权重矩阵中的那些行

     但是线性分类器只能为每一个类学习一个模板

     我们可以把image 看作是高维空间中的一个点 然后线性分类器正在放入这些线性决策边界 来尝试分类

     问题来了

    如何选择正确的W 下节讲~

  • 相关阅读:
    VMware虚拟机从一台电脑复制到另一台电脑
    JAVA系列之类加载机制详解
    Visual Studio 2019 C# winform CefSharp 中播放视频及全屏播放
    BioVendor sRAGE蛋白解决方案
    kafka如何保证消息不丢失
    用于图像恢复的即插即用 ADMM:定点收敛和应用(Matlab代码实现)
    十一、DS18B20温度传感器
    docker-compose deploy 高可用 elasticsearch TLS
    万字详解:推荐系统的知识与整体框架
    csrf防护机制
  • 原文地址:https://blog.csdn.net/m0_53292725/article/details/126905407