使用for filename in glob.glob读取txt文件,之后转化成np数组,然后扔给model.fit
中间网络部分省略 请大家帮帮忙 这样使用后model.fit的结果一成不变,如截图。
应该怎么做???
a_test = []
a_test_lable = []
for filename in glob.glob('E:/datasets/demon/target_1/test/*.txt'):
with open(filename) as f:
a_test.append(f.read().replace('\n',' ').strip(' ').split())
a_test_lable.append(1)
b_test = []
b_test_lable = []
for filename in glob.glob('E:/datasets/demon/target_2/test/*.txt'):
with open(filename) as f:
b_test.append(f.read().replace('\n',' ').strip(' ').split())
b_test_lable.append(0)
a_train = []
a_train_lable = []
for filename in glob.glob('E:/datasets/demon/target_1/train/*.txt'):
with open(filename) as f:
a_train.append(f.read().replace('\n',' ').strip(' ').split())
a_train_lable.append(1)
b_train = []
b_train_lable = []
for filename in glob.glob('E:/datasets/demon/target_2/train/*.txt'):
with open(filename) as f:
b_train.append(f.read().replace('\n',' ').strip(' ').split())
b_train_lable.append(0)
a_train = np.array(a_train, dtype = float)
a_train_lable = np.array(a_train_lable, dtype = int)
b_train = np.array(b_train, dtype = float)
b_train_lable = np.array(b_train_lable, dtype = int)
a_test = np.array(a_test, dtype = float)
a_test_lable = np.array(a_test_lable, dtype = int)
b_test = np.array(b_test, dtype = float)
b_test_lable = np.array(b_test_lable, dtype = int)
a_train = a_train.reshape(9000, 2, 2048, 1)
b_train = b_train.reshape(9000, 2, 2048, 1)
a_test = a_test.reshape(1000, 2, 2048, 1)
b_test = b_test.reshape(1000, 2, 2048, 1)
x_train = np.concatenate((a_train, b_train), axis = 0)
y_train = np.concatenate((a_train_lable, b_train_lable), axis = 0).reshape(18000, 1)
x_test = np.concatenate((a_test, b_test), axis = 0)
y_test = np.concatenate((a_test_lable, b_test_lable), axis = 0).reshape(2000, 1 )
model.fit(x_train, y_train, epochs = 200, verbose = 2, validation_split = 0.15)