コード例 #1
0
ファイル: mnist_show.py プロジェクト: MSMHMA/cmsc12300
                       help='Directory containing the MNIST files')
    parser.add_argument('-d', '--dataset', dest='dataset', action='store', required=True,
                        choices = ("TEST","TRAIN"),
                        help='Dataset to use (testing or training)')
    parser.add_argument('-i', '--index', dest='index', action='store', type=int, required=True,
                       help="Image index")

    args = parser.parse_args()
    
    return args

args = parse_command_line_arguments()

datadir = args.datadir
dataset = args.dataset
idx = args.index

if dataset == "TRAIN":
    data = MNISTReader("%s/train-images-idx3-ubyte" % datadir, "%s/train-labels-idx1-ubyte" % datadir)
elif dataset == "TEST":
    data = MNISTReader("%s/t10k-images-idx3-ubyte" % datadir, "%s/t10k-labels-idx1-ubyte" % datadir)

img = data.get_image(idx)

print img.as_asciiart()
print "Labelled as %d" % img.label

img.as_image().show()


コード例 #2
0
ファイル: knn_mnist.py プロジェクト: MSMHMA/cmsc12300
if idx == None:
    i = 0
    for p, known_label in test.images(as_array=True):
        label, nearest = knn(p, train.images(as_array=True), k)
        
        if label == known_label:
            x=""
        else:
            x="XXX"

        print "%i %i %i %s" % (i, known_label, label, x)
        sys.stdout.flush()

        i+=1
else:
    img = test.get_image(idx)

    label, nearest = knn(img.as_array(), train.images(as_array=True), k)

    print "K-NEAREST NEIGHBORS"
    print "============================================================"
    print
    for dist, nearpoint, nearlabel  in nearest:
        print MNISTImage(nearpoint, nearlabel, 28, 28).as_asciiart()
        print

    print "CLASSIFIED IMAGE"
    print "============================================================"
    print
    print img.as_asciiart()
    print 
コード例 #3
0
ファイル: knn_mnist.py プロジェクト: ykaravas/cmsc12300
if idx == None:
    i = 0
    for p, known_label in test.images(as_array=True):
        label, nearest = knn(p, train.images(as_array=True), k)

        if label == known_label:
            x = ""
        else:
            x = "XXX"

        print "%i %i %i %s" % (i, known_label, label, x)
        sys.stdout.flush()

        i += 1
else:
    img = test.get_image(idx)

    label, nearest = knn(img.as_array(), train.images(as_array=True), k)

    print "K-NEAREST NEIGHBORS"
    print "============================================================"
    print
    for dist, nearpoint, nearlabel in nearest:
        print MNISTImage(nearpoint, nearlabel, 28, 28).as_asciiart()
        print

    print "CLASSIFIED IMAGE"
    print "============================================================"
    print
    print img.as_asciiart()
    print
コード例 #4
0
ファイル: mnist_show.py プロジェクト: ykaravas/cmsc12300
                        dest='index',
                        action='store',
                        type=int,
                        required=True,
                        help="Image index")

    args = parser.parse_args()

    return args


args = parse_command_line_arguments()

datadir = args.datadir
dataset = args.dataset
idx = args.index

if dataset == "TRAIN":
    data = MNISTReader("%s/train-images-idx3-ubyte" % datadir,
                       "%s/train-labels-idx1-ubyte" % datadir)
elif dataset == "TEST":
    data = MNISTReader("%s/t10k-images-idx3-ubyte" % datadir,
                       "%s/t10k-labels-idx1-ubyte" % datadir)

img = data.get_image(idx)

print img.as_asciiart()
print "Labelled as %d" % img.label

img.as_image().show()