I'm going to do big things with TensorFlow, but I'm trying to start small.
I have small gray squares (with a little noise), and I want to classify them according to their color (for example, 3 categories: black, gray, white). I wrote a small Python class to generate squares and 1-hot vectors, and modified their base MNIST example to feed them.
But he does not know anything - for example. for 3 categories, he always guesses ≈33% correctly.
import tensorflow as tf import generate_data.generate_greyscale data_generator = generate_data.generate_greyscale.GenerateGreyScale(28, 28, 3, 0.05) ds = data_generator.generate_data(10000) ds_validation = data_generator.generate_data(500) xs = ds[0] ys = ds[1] num_categories = data_generator.num_categories x = tf.placeholder("float", [None, 28*28]) W = tf.Variable(tf.zeros([28*28, num_categories])) b = tf.Variable(tf.zeros([num_categories])) y = tf.nn.softmax(tf.matmul(x,W) + b) y_ = tf.placeholder("float", [None,num_categories]) cross_entropy = -tf.reduce_sum(y_*tf.log(y)) train_step = tf.train.GradientDescentOptimizer(0.01).minimize(cross_entropy) init = tf.initialize_all_variables() sess = tf.Session() sess.run(init)
My data generator looks like this:
import numpy as np import random class GenerateGreyScale(): def __init__(self, num_rows, num_cols, num_categories, noise): self.num_rows = num_rows self.num_cols = num_cols self.num_categories = num_categories
source share