def train_tensorflow(sess, trX, trY, train_steps, full_train, train_size, net_type, transform_dict, loss_type,
                     optimizer, optimizer_dict):

    # Set up input and output tensors.
    X = tf.placeholder("float", [None, trX.shape[1]])
    y = tf.placeholder("float", [None, trY.shape[1]])

    # Set up network.
    py_x = make_model(X, trX.shape[1], trY.shape[1], net_type, transform_dict)

    # Set up cost and training type.
    if loss_type == 'l2_loss':
        cost = tf.nn.l2_loss(tf.sub(py_x, y))
    elif loss_type == 'cross_entropy':
        cost = -tf.reduce_sum(y * tf.log(py_x))

    # Gets the optimizer to be used for training and sets it up.
    if type(optimizer) == str:
        train_op = optimizer_dict[optimizer][0](*optimizer_dict[optimizer][1]).minimize(cost)
    else:
        train_op = optimizer[0](*optimizer[1]).minimize(cost)

    predict_op = py_x

    # Initialize session.
    init = tf.initialize_all_variables()
    sess.run(init)

    # Trains given number of times
    try:
        for i in range(train_steps):

            # If full_train is selected, the trains on the full set of training data, in 100 sample increments.
            if full_train:
                for start, end in zip(range(0, len(trX), 100), range(100, len(trX), 100)):
                    sess.run(train_op, feed_dict={X: trX[start:end], y: trY[start:end]})

            # If full_train is not selected, then trains on a random set of samples from the training data.
            else:
                indices = random_index_list(train_size, len(trY))
                sess.run(train_op, feed_dict={X: trX[indices], y: trY[indices]})

    # If training throws an error for whatever reason, stops the program from breaking. Throws an error message and \
    # closes the session.
    except:
        print("Error during training")
        sess.close()
        return None

    return predict_op, X, y
Send an edit event to the peer.
dataset/ETHPy150Open calvinschmdt/EasyTensorflow/easy_tensorflow/tf_functions.py/train_tensorflow--crossover with--dataset/ETHPy150Open nlloyd/SubliminalCollaborator/libs/sub_collab/peer/basic.py/BasicPeer.sendEdit