sess.run(init) p = 0 count = 0 temp_acc = 0 temp_loss = 0 acc_list = [] loss_list = [] epoch_list = [] val_acc = [] val_loss = [] val_epoch_list = [] file_val = open('val.txt', 'a') # print(len(val_file_list)) print("即将开始读取数据") data, label, _ = TFRecordReader(train_file, 0) label = tf.cast(label, tf.int32) label = tf.one_hot(label, 2) label = sess.run(label) # print("hsuchausihcashdckuashckjasgcjsakhdsagfhdsugfoidsbfvjhsdhfsd") # print(label) val_data, val_label, _ = TFRecordReader(val_file, 0) val_data = val_data[:20] val_label = val_label[:20] val_label = tf.cast(val_label, tf.int32) val_label = tf.one_hot(val_label, 2) val_label = sess.run(val_label) val_label = val_label.reshape(len(val_label) * 1024, 2) val_data = val_data.reshape(len(val_data) * 1024, 1, num_input) # label
optimizer = tf.train.AdamOptimizer(learning_rate=learning_rate) train_process = optimizer.minimize(loss_op) # 定义准确率 acc = tf.reduce_mean( tf.cast(tf.equal(tf.argmax(prediction, 1), tf.argmax(Y, 1)), tf.float32)) # 保存模型 meraged = tf.summary.merge_all() tf.add_to_collection('loss', loss_op) tf.add_to_collection('accuracy', acc) tf.add_to_collection('prediction', prediction) # 初始化变量 init = tf.global_variables_initializer() # tf.get_default_graph().finalize() data, label, _ = TFRecordReader(train_file, 0) label = tf.cast(label, tf.int32) label = tf.one_hot(label, 2) data = tf.reshape(data, [5000, 1024, 30]) val_data, val_label, _ = TFRecordReader(val_file, 0) val_data = val_data[:20] val_label = val_label[:20] val_label = tf.cast(val_label, tf.int32) val_label = tf.one_hot(val_label, 2) val_label = tf.reshape(val_label, [20 * 1024, 2]) val_data = tf.reshape(val_data, [20, 1024, num_input]) with tf.Session() as sess: sess.run(init) # 读取数据,调整shape,保证输入无误