Ejemplo n.º 1
0
import numpy as np
import matplotlib.pyplot as plt
from sparse_autoencoder import SparseAutoencoder, sample_training_images

training_data = sample_training_images()[:100, :]
encoder = SparseAutoencoder(rho=0.01, L=0.0001, beta=3)
error, analytical_grad, numerical_grad = encoder.check_grad(training_data)
print "Gradient Error:", error

plt.plot(analytical_grad, numerical_grad, 'ro')
plt.plot(
    [np.min(analytical_grad), np.max(analytical_grad)],
    [np.min(analytical_grad), np.max(analytical_grad)], 'k-')
plt.xlabel('Analytical')
plt.ylabel('Numerical')
plt.show()
Ejemplo n.º 2
0
import numpy as np
import matplotlib.pyplot as plt
from sparse_autoencoder import SparseAutoencoder, sample_training_images

training_data = sample_training_images()[:100, :]
encoder = SparseAutoencoder(rho=0.01, L=0.0001, beta=3)
error, analytical_grad, numerical_grad = encoder.check_grad(training_data)
print "Gradient Error:", error

plt.plot(analytical_grad, numerical_grad, 'ro')
plt.plot([np.min(analytical_grad), np.max(analytical_grad)],
         [np.min(analytical_grad), np.max(analytical_grad)], 'k-')
plt.xlabel('Analytical')
plt.ylabel('Numerical')
plt.show()
Ejemplo n.º 3
0
import matplotlib.pyplot as plt
from sparse_autoencoder import (SparseAutoencoder, sample_training_images,
                                PATCH_SIZE)

training_data = sample_training_images()

encoder = SparseAutoencoder(hidden_size=25, rho=0.01, L=0.0001, beta=3)
encoder.train(training_data)

w1 = encoder.params.w1

fig = plt.figure()
for i in xrange(w1.shape[-1]):
    image = w1[:, i].reshape(*PATCH_SIZE)
    ax = fig.add_subplot(5, 5, i + 1)
    ax.imshow(image, cmap='binary')
    plt.axis('off')
plt.show()
Ejemplo n.º 4
0
import matplotlib.pyplot as plt
from sparse_autoencoder import (
    SparseAutoencoder, sample_training_images, PATCH_SIZE)

training_data = sample_training_images()

encoder = SparseAutoencoder(hidden_size=25, rho=0.01, L=0.0001, beta=3)
encoder.train(training_data)

w1 = encoder.params.w1

fig = plt.figure()
for i in xrange(w1.shape[-1]):
    image = w1[:, i].reshape(*PATCH_SIZE)
    ax = fig.add_subplot(5, 5, i+1)
    ax.imshow(image, cmap='binary')
    plt.axis('off')
plt.show()
Ejemplo n.º 5
0
def readFrames(directory, which_set, timestamps, patch_pose):
    videos = []

    videos = [name for name in os.listdir(directory, which_set)]
    videos.sort()

    num_patch = np.zeros((len(np.unique(timestamps)), 1))
    i = 0
    for timestamp in timestamps:
        num_patch[i, 0] = np.sum((timestamps == timestamp) * 1)
        i += 1

    for video in videos:
        frames = []

        orientationFileNames = [
            os.path.join(directory, video, 'Orientation', name)
            for name in os.listdir(
                os.path.join(directory, video, 'Orientation'))
        ]
        tempGradientFileNames = [
            os.path.join(directory, video, 'TempGradient', name)
            for name in os.listdir(
                os.path.join(directory, video, 'TempGradient'))
        ]
        timeStampsFileNames = [
            os.path.join(directory, video, 'TimeStamps',
                         name) for name in os.listdir(
                             os.path.join(directory, video, 'TimeStamps'))
        ]
        orientationFileNames.sort()
        tempGradientFileNames.sort()
        timeStampsFileNames.sort()

        for i in range(len(orientationFileNames)):
            all_orientation = scio.loadmat(
                orientationFileNames[i])['filteredOrientationFrame']
            all_ox = scio.loadmat(tempGradientFileNames[i])['ox']
            all_oy = scio.loadmat(tempGradientFileNames[i])['oy']
            all_frequency = scio.loadmat(
                tempGradientFileNames[i])['posLastEventPosition']
            all_postimestamp = scio.loadmat(
                timeStampsFileNames[i])['posTimeStamp']

            frames.append(all_orientation)
            frames.append(all_ox)
            frames.append(all_oy)
            frames.append(all_frequency)
            frames.append(all_postimestamp)

        n_feature = 5

        inputNodes = selected_patchs(frames, num_patch, patch_pose, n_feature)
        input_size = inputNodes.shape[0]
        hidden_size = inputNodes / n_feature
        if which_set is 'train':
            model = SparseAutoencoder(input_size, hidden_size, 'Dining')
            globalD = model.train(inputNodes)
        if which_set is 'test':
            model = SparseAutoencoder(input_size, hidden_size, 'Dining')
            globalD = model.predict(inputNodes)
    return inputNodes