Image reader and feeder does not work right
Created by: SaviorD7
Hello! My data reader:
def upload_data(data_dir):
new_input = []
for label in labels:
path = os.path.join(data_dir, label)
class_num = np.array([labels.index(label)]).astype('int64')
#print(class_num)
for img in tqdm(os.listdir(path)):
img_arr = Image.open(os.path.join(path,img)).convert('L')
img_arr = img_arr.resize((150, 150), Image.ANTIALIAS)
res = np.array(img_arr).reshape( 1, 150, 150).astype(np.float32)
res = res / 255.0 * 2.0 - 1.0
data_dict = {}
data_dict['data'] = res
data_dict['label'] = class_num
new_input.append(data_dict)
return new_input
I use it in trainer :
uploaded_train_data = xray_dataset.upload_data(data_path_train)
uploaded_test_data = xray_dataset.upload_data(data_path_test)
train_data, test_data = xray_dataset.main()
def train_test(train_test_program):
acc_set = []
for data in uploaded_test_data:
acc_np = trainer.exe.run(program=train_test_program,
feed={'img': np.array([data['data']]).astype('float32'), 'label': np.array([data['label']]).astype('int64')},
fetch_list=["accuracy_0.tmp_0"])
acc_set.append(float(acc_np[0]))
acc_val_mean = np.array(acc_set).mean()
return acc_val_mean
And in train logs i Have next:
2020-09-11 21:31:04 Epoch 1 start train
Test with epoch 1, accuracy: 1.0
2020-09-11 21:31:11 Epoch 2 start train
Test with epoch 2, accuracy: 1.0
2020-09-11 21:31:16 Epoch 3 start train
Test with epoch 3, accuracy: 1.0
2020-09-11 21:31:21 Epoch 4 start train
Test with epoch 4, accuracy: 1.0
2020-09-11 21:31:26 Epoch 5 start train
Test with epoch 5, accuracy: 1.0
2020-09-11 21:31:31 Epoch 6 start train
Test with epoch 6, accuracy: 1.0
2020-09-11 21:31:36 Epoch 7 start train
....
During all training. What is wrong with my feeder now ?