def createLayer(index, numOfOutput): training_data = np.array(Datasplit[index], dtype=np.float32) training_label = np.array(DatasplitLabel[index], dtype=np.float32) test_data = np.array(Datatest[index], dtype=np.float32) test_label = np.array(DatatestLabel[index], dtype=np.float32) autoencoder = AutoEncoder(numOfOutput=numOfOutput, epochs=10) decoder_op, layer_1 = autoencoder.initial_autoencode_network('encoder_h1', 'encoder_b1', 'decoder_h1', 'decoder_b1', autoencoder._X) autoencoder.calculate_AutoEncoder(decoder_op, training_data, training_label, autoencoder._X) decoder_op, layer_2 = autoencoder.initial_autoencode_network('encoder_h2', 'encoder_b2', 'decoder_h2', 'decoder_b2', layer_1) autoencoder.calculate_AutoEncoder(decoder_op, training_data, training_label, layer_1) decoder_op, layer_3 = autoencoder.initial_autoencode_network('encoder_h3', 'encoder_b3', 'decoder_h3', 'decoder_b3', layer_2) autoencoder.calculate_AutoEncoder(decoder_op, training_data, training_label, layer_2) y_ = autoencoder.initial_mlp_network() with tf.device('/cpu:0'): training_label_onehot = sess.run( tf.one_hot(indices=training_label, depth=numOfOutput, dtype=np.float64)) test_label_onehot = sess.run( tf.one_hot(indices=test_label, depth=numOfOutput, dtype=np.float64)) cnn_accuricy, cnn_predict_label = autoencoder.calculate_session(y_, training_data, training_label_onehot, test_data, test_label_onehot) print(cnn_accuricy) return cnn_accuricy
training_data, training_label = read() test_data, test_label = read(dataset="testing") with tf.device('/cpu:0'): # One hot encoding training_label = sess.run( tf.one_hot(indices=training_label, depth=max(training_label + 1), dtype=np.float64)) test_label = sess.run( tf.one_hot(indices=test_label, depth=max(test_label + 1), dtype=np.float64)) autoencoder = AutoEncoder() decoder_op, layer_1 = autoencoder.initial_autoencode_network( 'encoder_h1', 'encoder_b1', 'decoder_h1', 'decoder_b1', autoencoder._X) autoencoder.calculate_AutoEncoder(decoder_op, training_data, training_label, autoencoder._X) decoder_op, layer_2 = autoencoder.initial_autoencode_network( 'encoder_h2', 'encoder_b2', 'decoder_h2', 'decoder_b2', layer_1) autoencoder.calculate_AutoEncoder(decoder_op, training_data, training_label, layer_1) decoder_op, layer_3 = autoencoder.initial_autoencode_network( 'encoder_h3', 'encoder_b3', 'decoder_h3', 'decoder_b3', layer_2) autoencoder.calculate_AutoEncoder(decoder_op, training_data, training_label, layer_2) y_ = autoencoder.initial_mlp_network() cnn_accuricy, cnn_predict_label = autoencoder.calculate_session( y_, training_data, training_label, test_data, test_label) print(cnn_accuricy)