import pandas as pd
import numpy as np
import os 
from scipy import stats
from sklearn.metrics import roc_auc_score,classification_report
import itertools

out_csv = '/media/htic/Balamurali/Glaucoma_models/classification_results.csv'
src_path = '/media/htic/Balamurali/Glaucoma_models/'
test_data_len = 400
color_space = ['LAB','Normalized','PseudoDepth']
models = ['resnet152']#,'densenet201','resnet101','densenet169']
score_np = np.empty([test_data_len,0])
pred_np  = np.empty([test_data_len,0])



# Change for test
is_test  = False
csv_name = 'output.csv' 

for model in models:

	for color in color_space:

		csv_path   = os.path.join(src_path,'{}_{}'.format(model,color),csv_name)
		pd_data    = pd.read_csv(csv_path)
		file_names = pd_data['FileName'].values.reshape(400,1)
		pred_data  = pd_data['Predicted'].values.reshape(400,1)
		score_data = pd_data['Glaucoma Risk'].values.reshape(400,1)
		pred_np    = np.hstack([pred_np,pred_data])
		score_np   = np.hstack([score_np,score_data])

		# break
	# break
#print (file_names)
best_predict,_ = stats.mode(pred_np,axis=1)
best_predict = best_predict.astype(np.uint8)

score_np_min = np.min(score_np,axis=1).reshape(400,1)
score_np_max = np.max(score_np,axis=1).reshape(400,1)

zero_mask = np.where(best_predict == 0)
one_mask  = np.where(best_predict == 1)

print(zero_mask[0].shape)

result_score = np.zeros([400,1])
result_score[zero_mask] = score_np_max[zero_mask]
result_score[one_mask]  = score_np_min[one_mask]

# print (result_score)

if is_test:
	gt = np.zeros((400,1))
	gt[:40] = 1
	# print(gt)
	print(roc_auc_score(gt,result_score)) 


result = np.hstack([file_names,result_score])
df = pd.DataFrame(result)
df.to_csv(out_csv,header=['FileName','Glaucoma Risk'],index=False)

98980a00b8e976c7c027a4d14ae42f905f50841b
<mask token>

<mask token>
for model in models:
    for color in color_space:
        csv_path = os.path.join(src_path, '{}_{}'.format(model, color),
            csv_name)
        pd_data = pd.read_csv(csv_path)
        file_names = pd_data['FileName'].values.reshape(400, 1)
        pred_data = pd_data['Predicted'].values.reshape(400, 1)
        score_data = pd_data['Glaucoma Risk'].values.reshape(400, 1)
        pred_np = np.hstack([pred_np, pred_data])
        score_np = np.hstack([score_np, score_data])
<mask token>
print(zero_mask[0].shape)
<mask token>
if is_test:
    gt = np.zeros((400, 1))
    gt[:40] = 1
    print(roc_auc_score(gt, result_score))
<mask token>
df.to_csv(out_csv, header=['FileName', 'Glaucoma Risk'], index=False)

<mask token>
out_csv = '/media/htic/Balamurali/Glaucoma_models/classification_results.csv'
src_path = '/media/htic/Balamurali/Glaucoma_models/'
test_data_len = 400
color_space = ['LAB', 'Normalized', 'PseudoDepth']
models = ['resnet152']
score_np = np.empty([test_data_len, 0])
pred_np = np.empty([test_data_len, 0])
is_test = False
csv_name = 'output.csv'
for model in models:
    for color in color_space:
        csv_path = os.path.join(src_path, '{}_{}'.format(model, color),
            csv_name)
        pd_data = pd.read_csv(csv_path)
        file_names = pd_data['FileName'].values.reshape(400, 1)
        pred_data = pd_data['Predicted'].values.reshape(400, 1)
        score_data = pd_data['Glaucoma Risk'].values.reshape(400, 1)
        pred_np = np.hstack([pred_np, pred_data])
        score_np = np.hstack([score_np, score_data])
best_predict, _ = stats.mode(pred_np, axis=1)
best_predict = best_predict.astype(np.uint8)
score_np_min = np.min(score_np, axis=1).reshape(400, 1)
score_np_max = np.max(score_np, axis=1).reshape(400, 1)
zero_mask = np.where(best_predict == 0)
one_mask = np.where(best_predict == 1)
print(zero_mask[0].shape)
result_score = np.zeros([400, 1])
result_score[zero_mask] = score_np_max[zero_mask]
result_score[one_mask] = score_np_min[one_mask]
if is_test:
    gt = np.zeros((400, 1))
    gt[:40] = 1
    print(roc_auc_score(gt, result_score))
result = np.hstack([file_names, result_score])
df = pd.DataFrame(result)
df.to_csv(out_csv, header=['FileName', 'Glaucoma Risk'], index=False)

import pandas as pd
import numpy as np
import os
from scipy import stats
from sklearn.metrics import roc_auc_score, classification_report
import itertools
out_csv = '/media/htic/Balamurali/Glaucoma_models/classification_results.csv'
src_path = '/media/htic/Balamurali/Glaucoma_models/'
test_data_len = 400
color_space = ['LAB', 'Normalized', 'PseudoDepth']
models = ['resnet152']
score_np = np.empty([test_data_len, 0])
pred_np = np.empty([test_data_len, 0])
is_test = False
csv_name = 'output.csv'
for model in models:
    for color in color_space:
        csv_path = os.path.join(src_path, '{}_{}'.format(model, color),
            csv_name)
        pd_data = pd.read_csv(csv_path)
        file_names = pd_data['FileName'].values.reshape(400, 1)
        pred_data = pd_data['Predicted'].values.reshape(400, 1)
        score_data = pd_data['Glaucoma Risk'].values.reshape(400, 1)
        pred_np = np.hstack([pred_np, pred_data])
        score_np = np.hstack([score_np, score_data])
best_predict, _ = stats.mode(pred_np, axis=1)
best_predict = best_predict.astype(np.uint8)
score_np_min = np.min(score_np, axis=1).reshape(400, 1)
score_np_max = np.max(score_np, axis=1).reshape(400, 1)
zero_mask = np.where(best_predict == 0)
one_mask = np.where(best_predict == 1)
print(zero_mask[0].shape)
result_score = np.zeros([400, 1])
result_score[zero_mask] = score_np_max[zero_mask]
result_score[one_mask] = score_np_min[one_mask]
if is_test:
    gt = np.zeros((400, 1))
    gt[:40] = 1
    print(roc_auc_score(gt, result_score))
result = np.hstack([file_names, result_score])
df = pd.DataFrame(result)
df.to_csv(out_csv, header=['FileName', 'Glaucoma Risk'], index=False)

import pandas as pd
import numpy as np
import os 
from scipy import stats
from sklearn.metrics import roc_auc_score,classification_report
import itertools

out_csv = '/media/htic/Balamurali/Glaucoma_models/classification_results.csv'
src_path = '/media/htic/Balamurali/Glaucoma_models/'
test_data_len = 400
color_space = ['LAB','Normalized','PseudoDepth']
models = ['resnet152']#,'densenet201','resnet101','densenet169']
score_np = np.empty([test_data_len,0])
pred_np  = np.empty([test_data_len,0])



# Change for test
is_test  = False
csv_name = 'output.csv' 

for model in models:

	for color in color_space:

		csv_path   = os.path.join(src_path,'{}_{}'.format(model,color),csv_name)
		pd_data    = pd.read_csv(csv_path)
		file_names = pd_data['FileName'].values.reshape(400,1)
		pred_data  = pd_data['Predicted'].values.reshape(400,1)
		score_data = pd_data['Glaucoma Risk'].values.reshape(400,1)
		pred_np    = np.hstack([pred_np,pred_data])
		score_np   = np.hstack([score_np,score_data])

		# break
	# break
#print (file_names)
best_predict,_ = stats.mode(pred_np,axis=1)
best_predict = best_predict.astype(np.uint8)

score_np_min = np.min(score_np,axis=1).reshape(400,1)
score_np_max = np.max(score_np,axis=1).reshape(400,1)

zero_mask = np.where(best_predict == 0)
one_mask  = np.where(best_predict == 1)

print(zero_mask[0].shape)

result_score = np.zeros([400,1])
result_score[zero_mask] = score_np_max[zero_mask]
result_score[one_mask]  = score_np_min[one_mask]

# print (result_score)

if is_test:
	gt = np.zeros((400,1))
	gt[:40] = 1
	# print(gt)
	print(roc_auc_score(gt,result_score)) 


result = np.hstack([file_names,result_score])
df = pd.DataFrame(result)
df.to_csv(out_csv,header=['FileName','Glaucoma Risk'],index=False)
