def test_getRandomBatch(): """Batch tensors should have the correct shape""" batchSize = 22 X, y = qrcodes.getRandomBatch(batchSize) y = np.asarray(y) assert_equals((batchSize, qrcodes.IMAGE_SIZE, qrcodes.IMAGE_SIZE, 1), X.shape) assert_equals((batchSize, len(qrcodes.CHARACTER_SET)), y.shape)
def weight_variable(shape): initial = tf.truncated_normal(shape, stddev=0.1, name="weights") return tf.Variable(initial) def bias_variable(shape): initial = tf.constant(0.1, shape=shape, name="bias") return tf.Variable(initial) # Validation set NUM_TEST_IMAGES = 5000 print("Creating {} random test images ... ".format(NUM_TEST_IMAGES), end="", flush=True) test_images, test_labels = qrcodes.getRandomBatch(size=NUM_TEST_IMAGES) print("done") # Inputs with tf.name_scope("input"): x_image = tf.placeholder(tf.float32, shape=[None, IMAGE_SIZE, IMAGE_SIZE, 1], name="x_image") y_ = tf.placeholder(tf.float32, shape=[None, NUM_OUTPUTS], name="y_") tf.summary.image('x_image', x_image, max_outputs=3) with tf.name_scope("dropout_input"): keep_prob = tf.placeholder(tf.float32, name="keep_probability") # Fully connected layer NUM_FULLY_CONNECTED_1 = 128
NUM_TRAIN_IMAGES = 500 NUM_VALID_IMAGES = 50 NUM_TEST_IMAGES = 5 # HSIZE_IMAGE = 21 VSIZE_IMAGE = 21 # #img = qrcode.make("asdfgjkl1234") #img.save('./tmp.png') #s # Validation set #print("Creating {} random test images ... ".format(NUM_TEST_IMAGES), end="", flush=True) train_images, train_labels = qrcodes.getRandomBatch(size=NUM_TRAIN_IMAGES) #print("done") train_images = train_images.reshape(NUM_TRAIN_IMAGES, HSIZE_IMAGE, VSIZE_IMAGE) print(train_images.shape) #- Display Train Image sample for i in range(3 * 4): plt.subplot(3, 4, i + 1) plt.imshow(train_images[i], 'gray') plt.suptitle("train images", fontsize=12) plt.show() #print(string(train_labels[0]))