<jupyter_start><jupyter_text>[Angle closure Glaucoma Evaluation Challenge](https://age.grand-challenge.org/Details/) Angle closure classification Baseline  requirement install<jupyter_code>!pip install xlrd<jupyter_output><empty_output><jupyter_text>Zip File ExtractAssume `Training100.zip` and `Validation_ASOCT_Image.zip` are stored @ `./AGE_challenge Baseline/datasets/`<jupyter_code>!unzip -q ../datasets/Training100.zip -d ../datasets/
!unzip -q ../datasets/Validation_ASOCT_Image.zip -d ../datasets/<jupyter_output><empty_output><jupyter_text>Explore Data & Train/Val split<jupyter_code>import numpy as np
import csv
import matplotlib.pyplot as plt
import cv2
import os, shutil
import pprint
import pandas as pd

%matplotlib inline
data_root_path = "../datasets/Training100/"
xlsx_file_path = os.path.join(data_root_path, "Training100_Location.xlsx")

# Load
image_path = os.path.join(data_root_path, "ASOCT_Image")
label_file_path = os.path.join(data_root_path, "train_cls.csv")

# Save
train_file_path = os.path.join(data_root_path, "cls_train_split.csv")
val_file_path = os.path.join(data_root_path, "cls_val_split.csv")
xlsx_file = pd.read_excel(xlsx_file_path)
xlsx_file.to_csv(label_file_path, 
                    index=False, columns=['ASOCT_Name', 'Left_Label', 'Right_Label'])
xlsx_file.head()
data_list = []

with open(label_file_path,'r') as f:  
    lines=csv.reader(f)  
    for key, line in enumerate(lines):  
        data_list.append(line)
        
pprint.pprint(data_list[:5])
#                             left, right
# negative sample (label==0): 1280, 1280
# positive sample (label==1): 320,  320
left_label_counter = [0, 0]
right_label_counter = [0, 0]

for line in data_list[1:]:
    file_name, l_label, r_label = line
    left_label_counter[int(l_label)] += 1
    right_label_counter[int(r_label)] += 1
    
print(left_label_counter)
print(right_label_counter)
# Left label == Right label, in **TRAINING SET**
for line in data_list[1:]:
    file_name, l_label, r_label = line
    if int(l_label) != int(r_label):
        print(line)<jupyter_output><empty_output><jupyter_text>Train/Val Split<jupyter_code>def train_val_split(data_list, train_ratio=0.8, shuffle_seed=42):
    testee_list = list(set( [line[0].split("-")[0] for line in data_list[1:]] ))
    
    # Split by patient id, prevent data leakage
    val_testee_idx = np.random.choice(testee_list, int(len(testee_list) * (1-train_ratio)), replace=False)

    train_list = []
    val_list = []
    
    for line in data_list[1:]:
        file_name, _, _ = line
        if file_name.split("-")[0] in val_testee_idx:
            val_list.append(line)
        else:
            train_list.append(line)
            
    return train_list, val_list
train_data_list, val_data_list = train_val_split(data_list)
print(len(train_data_list))
print(len(val_data_list))
# Write to files
with open(train_file_path, "w+") as f:
    for line in train_data_list:
#         file_name, l_label, r_label = line
        f.write("{},{},{}\n".format(*line))
    
with open(val_file_path, "w+") as f:
    for line in val_data_list:
        f.write("{},{},{}\n".format(*line))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1293783527926791, 'fraction_numerical': 0.01514673398548438, 'mean_word_length': 4.309882747068677, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '155194', 'license': 'Apache-2.0', 'n_tokens_mistral': 1211, 'n_tokens_neox': 1151, 'n_words': 220, 'path': 'CV/AGEchallenge/Classification/1. PrepareData.ipynb', 'repo_name': 'parap1uie-s/Research', 'size': '3169'}