Example #1
0
def run():
    from dataset_reader import read_cifar10
    data = read_cifar10('datasets/cifar-10-batches-py/', one_hot=True)
    train_x = data['train_x']
    train_y = data['train_y']
    test_x = data['test_x']
    test_y = data['test_y']
    text_labels = data['text_labels']
    label_count = len(text_labels)
    pi = np.random.permutation(len(train_x))
    train_x, train_y = train_x[pi], train_y[pi]
    print "Train:", np.shape(train_x), np.shape(train_y)
    print "Test:", np.shape(test_x), np.shape(test_y)
    model=DCNN()
    model.set_epoch(300)
    model.set_batch_size(100)
    data = {'train_data': train_x,
            'train_labels': train_y,
            'test_data': test_x,
            'test_labels': test_y}
    model.train(data, [32 , 32 , 3], label_count, 40)
Example #2
0
from sklearn.svm import SVC
import numpy as np
import utils
import pca
def get_accuracy(actual,pred):
    return float(np.sum(np.equal(pred,actual)))/float(len(actual))*100


## loading Cifar10 dataset
from dataset_reader import read_cifar10
data = read_cifar10('cifar-10-batches-py/', one_hot=False)
train_x=data['train_x']
train_y=data['train_y']
test_x=data['test_x']
test_y=data['test_y']
text_labels=data['text_labels']

#p=pca.pca()
#p.train(train_x)
#train_x=p.transform(train_x)
#test_x=p.transform(test_x)
### Checking DATAset shape
print train_x.shape, train_y.shape, test_x.shape, test_y.shape
train_y=train_y.reshape(60000)
test_y=test_y.reshape(10000)

#creating a classifer Object
clf = SVC(C=1.0,decision_function_shape='ovr')
print "Training ...... "
#clf.fit(train_x,train_y)
Example #3
0
                    new_location = sess.run(
                        mean_op,
                        feed_dict={mean_input: np.array(assigned_vects)})
                    # Assign value to appropriate variable
                    sess.run(cent_assigns[cluster_n],
                             feed_dict={centroid_value: new_location})
                print "iteration : ", iteration_n

            # Return centroids and assignments
            self.centroids_result = np.array(sess.run(centroids))
            self.assignments_result = np.array(sess.run(assignments))


import dataset_reader, utils

data = dataset_reader.read_cifar10('cifar-10-batches-py/', one_hot=False)
train_x = data['train_x']
train_y = data['train_y']
test_x = data['test_x']
test_y = data['test_y']
text_labels = data['text_labels']
print train_x.shape, train_y.shape, test_x.shape, test_y.shape
no_of_clusters = 10
model = KMeans()
model.set_epoch(10)
model.train(np.float32(train_x), no_of_clusters)
utils.save_model(model, "k-means-000")
model = utils.load_model("k-means-000")
print "No Of Cluster : ", model.no_of_clusters
print "homogeneity score : ", model.homogeneity_score(train_y)
print "Completeness : ", model.completeness_score(train_y)