Пример #1
0
if classifier.W is not None:
    tmpW = classifier.W[:-1, :]
    tmpW = tmpW.reshape(32, 32, 3, 10)
    tmpWMin, tmpWMax = np.min(tmpW), np.max(tmpW)
    for i in range(numClasses):
        plt.subplot(2, 5, i + 1)
        plt.title(classesName[i])
        wPlot = 255.0 * (tmpW[:, :, :, i].squeeze() - tmpWMin) / (tmpWMax -
                                                                  tmpWMin)
        plt.imshow(wPlot.astype('uint8'))
    plt.savefig(baseDir + 'svm1.png')
    plt.clf()

# Training classifier
startTime = time.time()
classifier.train(xTrain, yTrain, lr=1e-7, reg=5e4, iter=1500, verbose=True)
print('Training time: {0}'.format(time.time() - startTime))

# Calculate accuracy (Should get around this)
# Training acc:   37.61%
# Validating acc: 37.0%
# Testing acc:    37.38%
print('Training acc:   {0}%'.format(classifier.calAccuracy(xTrain, yTrain)))
print('Validating acc: {0}%'.format(classifier.calAccuracy(xVal, yVal)))
print('Testing acc:    {0}%'.format(classifier.calAccuracy(xTest, yTest)))

# Show some weight for each class after training
if classifier.W is not None:
    tmpW = classifier.W[:-1, :]
    tmpW = tmpW.reshape(32, 32, 3, 10)
    tmpWMin, tmpWMax = np.min(tmpW), np.max(tmpW)
if classifier.W is not None:
    tmpW = classifier.W[:-1, :]
    tmpW = tmpW.reshape(32, 32, 3, 10)
    tmpWMin, tmpWMax = np.min(tmpW), np.max(tmpW)
    for i in range(numClasses):
        plt.subplot(2, 5, i + 1)
        plt.title(classesName[i])
        wPlot = 255.0 * (tmpW[:, :, :, i].squeeze() - tmpWMin) / (tmpWMax -
                                                                  tmpWMin)
        plt.imshow(wPlot.astype('uint8'))
    plt.savefig(baseDir + 'svm1.png')
    plt.clf()

# Training classifier
startTime = time.time()
classifier.train(xTrain, yTrain, lr=1e-7, reg=5e4, iter=1500, verbose=True)
print('Training time: {0}'.format(time.time() - startTime))

# Calculate accuracy (Should get around this)
# Training acc:   37.61%
# Validating acc: 37.0%
# Testing acc:    37.38%
print('Training acc:   {0}%'.format(classifier.calAccuracy(xTrain, yTrain)))
print('Validating acc: {0}%'.format(classifier.calAccuracy(xVal, yVal)))
print('Testing acc:    {0}%'.format(classifier.calAccuracy(xTest, yTest)))

# Show some weight for each class after training
if classifier.W is not None:
    tmpW = classifier.W[:-1, :]
    tmpW = tmpW.reshape(32, 32, 3, 10)
    tmpWMin, tmpWMax = np.min(tmpW), np.max(tmpW)
if classifier.W is not None:
    tmpW = classifier.W[:-1, :]
    tmpW = tmpW.reshape(32, 32, 3, 10)
    tmpWMin, tmpWMax = np.min(tmpW), np.max(tmpW)
    for i in range(numClasses):
        plt.subplot(2, 5, i + 1)
        plt.title(classesName[i])
        wPlot = 255.0 * (tmpW[:, :, :, i].squeeze() - tmpWMin) / (tmpWMax -
                                                                  tmpWMin)
        plt.imshow(wPlot.astype('uint8'))
    plt.savefig(baseDir + 'svm1.png')
    plt.clf()

# Training classifier
startTime = time.time()
classifier.train(xTrain, yTrain, lr=1e-7, reg=5e4, iter=1500, verbose=True)
print('Training time: {0}'.format(time.time() - startTime))

# Calculate accuracy (Should get around this)
# Training acc:   37.61%
# Validating acc: 37.0%
# Testing acc:    37.38%
print('Training acc:   {0}%'.format(classifier.calAccuracy(xTrain, yTrain)))
print('Validating acc: {0}%'.format(classifier.calAccuracy(xVal, yVal)))
print('Testing acc:    {0}%'.format(classifier.calAccuracy(xTest, yTest)))

# Show some weight for each class after training
if classifier.W is not None:
    tmpW = classifier.W[:-1, :]
    tmpW = tmpW.reshape(32, 32, 3, 10)
    tmpWMin, tmpWMax = np.min(tmpW), np.max(tmpW)
Пример #4
0
if classifier.W is not None:
    tmpW = classifier.W[:-1, :]
    tmpW = tmpW.reshape(32, 32, 3, 10)
    tmpWMin, tmpWMax = np.min(tmpW), np.max(tmpW)
    for i in range(numClasses):
        plt.subplot(2, 5, i+1)
        plt.title(classesName[i])
        wPlot = 255.0 * (tmpW[:, :, :, i].squeeze() - tmpWMin) / (tmpWMax - tmpWMin)
        plt.imshow(wPlot.astype('uint8'))
    plt.savefig(baseDir+'svm1.png')
    plt.clf()

# Training classifier
startTime = time.time()

classifier.train(xTrain, yTrain, lr=1e-7, reg=5e4, iter=1500 ,verbose=True)
print ('Training time: {0}'.format(time.time() - startTime))

# Calculate accuracy (Should get around this)
# Training acc:   37.61%
# Validating acc: 37.0%
# Testing acc:    37.38%
print ('Training acc:   {0}%'.format(classifier.calAccuracy(xTrain, yTrain)))
print ('Validating acc: {0}%'.format(classifier.calAccuracy(xVal, yVal)))
print ('Testing acc:    {0}%'.format(classifier.calAccuracy(xTest, yTest)))

# Show some weight for each class after training
if classifier.W is not None:
    tmpW = classifier.W[:-1, :]
    tmpW = tmpW.reshape(32, 32, 3, 10)
    tmpWMin, tmpWMax = np.min(tmpW), np.max(tmpW)
Пример #5
0
if classifier.W is not None:
    tmpW = classifier.W[:-1, :]
    tmpW = tmpW.reshape(32, 32, 3, 10)
    tmpWMin, tmpWMax = np.min(tmpW), np.max(tmpW)
    for i in range(numClasses):
        plt.subplot(2, 5, i + 1)
        plt.title(classesName[i])
        wPlot = 255.0 * (tmpW[:, :, :, i].squeeze() - tmpWMin) / (tmpWMax -
                                                                  tmpWMin)
        plt.imshow(wPlot.astype('uint8'))
    plt.savefig(baseDir + 'svm1.png')
    plt.clf()

# Training classifier
startTime = time.time()
classifier.train(xTrain, yTrain, lr=1e-7, reg=5e4, iter=1500, verbose=True)
print('Training time: {0}'.format(time.time() - startTime))

# Calculate accuracy (Should get around this)
# Training acc:   37.61%
# Validating acc: 37.0%
# Testing acc:    37.38%
print('Training acc:   {0}%'.format(classifier.calAccuracy(xTrain, yTrain)))
print('Validating acc: {0}%'.format(classifier.calAccuracy(xVal, yVal)))
print('Testing acc:    {0}%'.format(classifier.calAccuracy(xTest, yTest)))

# Show some weight for each class after training
if classifier.W is not None:
    tmpW = classifier.W[:-1, :]
    tmpW = tmpW.reshape(32, 32, 3, 10)
    tmpWMin, tmpWMax = np.min(tmpW), np.max(tmpW)
Пример #6
0
# Show weight for each class before training
if classifier.W is not None:
    tmpW = classifier.W[:-1, :]
    tmpW = tmpW.reshape(32, 32, 3, 10)
    tmpWMin, tmpWMax = np.min(tmpW), np.max(tmpW)
    for i in range(numClasses):
        plt.subplot(2, 5, i+1)
        plt.title(classesName[i])
        wPlot = 255.0 * (tmpW[:, :, :, i].squeeze() - tmpWMin) / (tmpWMax - tmpWMin)
        plt.imshow(wPlot.astype('uint8'))
    plt.savefig(baseDir+'svm1.png')
    plt.clf()

# Training classifier
startTime = time.time()
classifier.train(xTrain, yTrain, lr=1e-7, reg=5e4, iter=1500 ,verbose=True)
print ('Training time: {0}'.format(time.time() - startTime))

# Calculate accuracy (Should get around this)
# Training acc:   37.61%
# Validating acc: 37.0%
# Testing acc:    37.38%
print ('Training acc:   {0}%'.format(classifier.calAccuracy(xTrain, yTrain)))
print ('Validating acc: {0}%'.format(classifier.calAccuracy(xVal, yVal)))
print ('Testing acc:    {0}%'.format(classifier.calAccuracy(xTest, yTest)))

# Show some weight for each class after training
if classifier.W is not None:
    tmpW = classifier.W[:-1, :]
    tmpW = tmpW.reshape(32, 32, 3, 10)
    tmpWMin, tmpWMax = np.min(tmpW), np.max(tmpW)
if classifier.W is not None:
    tmpW = classifier.W[:-1, :]
    tmpW = tmpW.reshape(32, 32, 3, 10)
    tmpWMin, tmpWMax = np.min(tmpW), np.max(tmpW)
    for i in range(numClasses):
        plt.subplot(2, 5, i + 1)
        plt.title(classesName[i])
        wPlot = 255.0 * (tmpW[:, :, :, i].squeeze() - tmpWMin) / (tmpWMax -
                                                                  tmpWMin)
        plt.imshow(wPlot.astype('uint8'))
    plt.savefig(baseDir + 'svm1.png')
    plt.clf()

# Training classifier
startTime = time.time()
classifier.train(xTrain, yTrain, lr=1e-7, reg=5e4, iter=1500, verbose=True)
print('Training time: {0}'.format(time.time() - startTime))

# Calculate accuracy (Should get around this)
# Training acc:   37.61%
# Validating acc: 37.0%
# Testing acc:    37.38%
print('Training acc:   {0}%'.format(classifier.calAccuracy(xTrain, yTrain)))
print('Validating acc: {0}%'.format(classifier.calAccuracy(xVal, yVal)))
print('Testing acc:    {0}%'.format(classifier.calAccuracy(xTest, yTest)))

# Show some weight for each class after training
if classifier.W is not None:
    tmpW = classifier.W[:-1, :]
    tmpW = tmpW.reshape(32, 32, 3, 10)
    tmpWMin, tmpWMax = np.min(tmpW), np.max(tmpW)