示例#1
0
def test_func(caplog):
    caplog.set_level(logging.INFO)
    func()
    record1, record2 = caplog.records
    assert record1.levelname == "INFO"  # not "debug", because logging.INFO is set
    assert record1.message == "An info message"
    assert record2.levelname == "ERROR"
    assert record2.message == "Cannot divide by 0"
    assert record2.exc_info[0] is ZeroDivisionError
示例#2
0
tf.summary.scalar('accuracy', accuracy)

# Merge all summaries together
merged_summary = tf.summary.merge_all()

num_epochs = 100
batch_size = 100

with tf.Session() as sess:
    # Initialize all variables
    sess.run(tf.global_variables_initializer())

    #################################
    import script
    image_for_structure = {x: data.test.images[:1]}
    script.func(sess, layer_fc2, image_for_structure)
    #################################

    # Add the model graph to TensorBoard
    writer.add_graph(sess.graph)

    # Loop over number of epochs
    for epoch in range(num_epochs):

        start_time = time.time()
        train_accuracy = 0

        for batch in range(0, int(len(data.train.labels) / batch_size)):

            # Get a batch of images and labels
            x_batch, y_true_batch = data.train.next_batch(batch_size)
示例#3
0
async def ytmusic(ctx, *, link):
    url = script.func(link)
    await ctx.send(url)
示例#4
0
loss = tf.losses.softmax_cross_entropy(onehot_labels=tf_y, logits=output)           # compute cost
train_op = tf.train.AdamOptimizer(LR).minimize(loss)

accuracy = tf.metrics.accuracy(          # return (acc, update_op), and create 2 local variables
    labels=tf.argmax(tf_y, axis=1), predictions=tf.argmax(output, axis=1),)[1]

sess = tf.Session()
init_op = tf.group(tf.global_variables_initializer(), tf.local_variables_initializer()) # the local var is for accuracy_op
sess.run(init_op)     # initialize var in graph



########################################################################################################__________________________________________________
import script
image_for_structure={tf_x: test_x[:1]}
script.func(sess,output,image_for_structure)
#script.func(output,image_for_structure)
########################################################################################################__________________________________________________



# training
for step in range(50):
    b_x, b_y = mnist.train.next_batch(BATCH_SIZE)
    _, loss_ = sess.run([train_op, loss], {tf_x: b_x, tf_y: b_y})
    if step % 50 == 0:
        accuracy_, flat_representation = sess.run([accuracy, flat], {tf_x: test_x, tf_y: test_y})
        print('Step:', step, '| train loss: %.4f' % loss_, '| test accuracy: %.2f' % accuracy_)


示例#5
0
 def test_func_err_none(self):
     test_param = None
     result = script.func(test_param)
     self.assertIsInstance(result, TypeError)
示例#6
0
 def test_func_err_string(self):
     test_param = 'string'
     result = script.func(test_param)
     self.assertIsInstance(result, ValueError)
示例#7
0
 def test_func(self):
     test_param = 10
     result = script.func(test_param)
     self.assertEqual(result, 20)