Esempio n. 1
0
        res = sess.run(
            [tf.nn.softmax(preds["n0"]),
             tf.nn.softmax(preds["n1"])],
            feed_dict={
                placeholders["i0"]: inputs["i0"],
                placeholders["i1"]: inputs["i1"]
            })
        sess.close()
    # Return both accuracies
    return accuracy_error(res[0], outputs["o0"]), accuracy_error(
        res[1], outputs["o1"])


if __name__ == "__main__":

    fashion_x_train, fashion_y_train, fashion_x_test, fashion_y_test = load_fashion(
    )
    mnist_x_train, mnist_y_train, mnist_x_test, mnist_y_test = load_mnist()

    OHEnc = OneHotEncoder(categories='auto')

    fashion_y_train = OHEnc.fit_transform(np.reshape(fashion_y_train,
                                                     (-1, 1))).toarray()

    fashion_y_test = OHEnc.fit_transform(np.reshape(fashion_y_test,
                                                    (-1, 1))).toarray()

    mnist_y_train = OHEnc.fit_transform(np.reshape(mnist_y_train,
                                                   (-1, 1))).toarray()

    mnist_y_test = OHEnc.fit_transform(np.reshape(mnist_y_test,
                                                  (-1, 1))).toarray()
Esempio n. 2
0
    return predictions


def eval_cnn_ae(preds, placeholders, sess, graph, inputs, _, __):
    with graph.as_default():
        res = sess.run(preds["n1"], feed_dict={placeholders["i0"]: inputs["i0"]})
        sess.close()
        if np.isnan(res).any():
            return 288,
        else:
            return mean_squared_error(np.reshape(res, (-1)), np.reshape(inputs["i0"], (-1))),


if __name__ == "__main__":

    x_train, y_train, x_test, y_test = load_fashion()

    x_train = np.expand_dims(x_train, axis=3)/255
    x_train = np.concatenate((x_train, x_train, x_train), axis=3)

    x_test = np.expand_dims(x_test, axis=3)/255
    x_test = np.concatenate((x_test, x_test, x_test), axis=3)

    OHEnc = OneHotEncoder(categories='auto')

    y_train = OHEnc.fit_transform(np.reshape(y_train, (-1, 1))).toarray()

    y_test = OHEnc.fit_transform(np.reshape(y_test, (-1, 1))).toarray()
    # Here we define a convolutional-transposed convolutional network combination
    e = Evolving(loss=train_cnn_ae, desc_list=[ConvDescriptor, TConvDescriptor], x_trains=[x_train], y_trains=[y_train], x_tests=[x_test], y_tests=[y_test], evaluation=eval_cnn_ae, batch_size=150, population=2, generations=10, n_inputs=[[28, 28, 3], [7, 7, 1]], n_outputs=[[49], [28, 28, 3]], cxp=0, mtp=1, hyperparameters = {"lrate": [0.1, 0.5, 1], "optimizer": [0, 1, 2]}, no_batch_norm=False, no_dropout=False)
    a = e.evolve()
Esempio n. 3
0
    predictions = np.sort(predictions, axis=1)
    predictions = np.mean(predictions, axis=0)

    return -np.sum([
        aux_preds[w] *
        np.log(aux_preds[w] / predictions[w]) if aux_preds[w] > 0 else 0
        for w in range(predictions.shape[0])
    ]),


if __name__ == "__main__":

    mobile_graph, model = load_model(
    )  # The model and its graph are used as global variables

    x_train, _, x_test, _ = load_fashion()
    # The GAN evolutive process is a common 2-DNN evolution
    e = Evolving(loss=gan_train,
                 desc_list=[MLPDescriptor, MLPDescriptor],
                 x_trains=[x_train],
                 y_trains=[x_train],
                 x_tests=[x_test],
                 y_tests=[x_test],
                 evaluation=gan_eval,
                 batch_size=150,
                 population=10,
                 generations=10,
                 n_inputs=[[28, 28], [10]],
                 n_outputs=[[1], [784]],
                 cxp=0.5,
                 mtp=0.5)