예제 #1
0
  x_image = nn_ops.conv2d_transpose(h_conv1 + b_conv1, W_conv1, [class_size,28,28,1], [1,1,1,1])
  x_image = tf.nn.relu(x_image)
  return x_image

x_image = rebuild_image()

########

# Do these have to be changed based on class size?
error = tf.reduce_sum(tf.pow(tf.reshape(x,[-1]) - tf.reshape(x_image, [-1]), 2))
train_step = tf.train.AdamOptimizer(1e-4).minimize(error)
sess.run(tf.initialize_all_variables())

# Put the file names of the images in order
image_names = list(map(lambda x: "train_images/" + str(x) + ".gz", range(class_size)))
images = np.array(list(map(lambda x: mo.idx_to_array(x), image_names)))
images = np.reshape(images, [class_size, 28*28])
#images = np.reshape(np.array([mo.idx_to_array('three.gz')]), [1,-1])/255.0
#oh_encodings = np.array([[1]])
oh_encodings = np.identity(class_size)
#fd = {x:three_im}

for i in range(iterations):
  if i % 20 == 0:
    print("step %d"%(i,))
    #print(tf.reduce_max(x_image).eval(feed_dict={y_:[oh_encodings[0]]}))
    train_accuracy = error.eval(feed_dict={x:images , y_:oh_encodings})
    print("CE: %s"%(train_accuracy,))
  train_step.run(feed_dict={x:images , y_:oh_encodings})

'''
예제 #2
0

x_image = rebuild_image()

########

# Do these have to be changed based on class size?
error = tf.reduce_sum(
    tf.pow(tf.reshape(x, [-1]) - tf.reshape(x_image, [-1]), 2))
train_step = tf.train.AdamOptimizer(1e-4).minimize(error)
sess.run(tf.initialize_all_variables())

# Put the file names of the images in order
image_names = list(
    map(lambda x: "train_images/" + str(x) + ".gz", range(class_size)))
images = np.array(list(map(lambda x: mo.idx_to_array(x), image_names)))
images = np.reshape(images, [class_size, 28 * 28])
#images = np.reshape(np.array([mo.idx_to_array('three.gz')]), [1,-1])/255.0
#oh_encodings = np.array([[1]])
oh_encodings = np.identity(class_size)
#fd = {x:three_im}

for i in range(iterations):
    if i % 20 == 0:
        print("step %d" % (i, ))
        #print(tf.reduce_max(x_image).eval(feed_dict={y_:[oh_encodings[0]]}))
        train_accuracy = error.eval(feed_dict={x: images, y_: oh_encodings})
        print("CE: %s" % (train_accuracy, ))
    train_step.run(feed_dict={x: images, y_: oh_encodings})
'''
  W_fc2 = weight_variable([class_size, fc_size])