<jupyter_start><jupyter_text>Plotting train vs val<jupyter_code>%matplotlib inline

import pandas as pd
import matplotlib.pyplot as plt
import numpy as np

import os 

def getDataframes(model_name): 
    val_filename = '/home/ubuntu/surgery-tool-detection/logs/{}/{}_validation.csv'.format(model_name, model_name) 
    val_df = pd.read_csv(val_filename) 
    train_filename = '/home/ubuntu/surgery-tool-detection/logs/{}/{}_train.csv'.format(model_name, model_name)
    train_df = pd.read_csv(train_filename) 
    return val_df, train_df 
model_name = '9.2_Model4' 

val_df, train_df = getDataframes(model_name) 

print(val_df) 
print(train_df) 

ax = val_df.plot('Epoch', 'Overall', label='Val Overall') 
train_df.plot('Epoch', 'Overall', ax=ax, label='Train Overall')  
val_df.plot('Epoch') 
train_df.plot('Epoch') 

fields = ['Overall', 'bovie', 'scalpel', 'forceps', 'needledriver'] 
for field in fields: 
    if field == "Overall": continue 
    ax = val_df.plot('Epoch', field, label='Val {}'.format(field)) 
    train_df.plot('Epoch', field, ax=ax, label='Train {}'.format(field))<jupyter_output><empty_output><jupyter_text>Plotting loss curves<jupyter_code>def getReducedLossDataframe(model_name): 
    loss_filename = '/home/ubuntu/surgery-tool-detection/logs/{}/{}_loss.csv'.format(model_name, model_name)
    loss_df = pd.read_csv(loss_filename)
    
    loss_dict = []
    for index, row in loss_df.iterrows():
        import math # 
        if math.isnan(row['Epoch']): continue # 
        epoch = int(row['Epoch'])
        if epoch > len(loss_dict):
            loss_dict.append(list(row))

    # Only takes the last iteration value for each epoch
    reduced_loss_df = pd.DataFrame(loss_dict, columns=['Epoch', 'Iteration', 'Classification Loss', 'Regression Loss', 'Running Loss'])
    return reduced_loss_df 

model_name = '9.2_Model4' 
reduced_loss_df = getReducedLossDataframe(model_name) 

reduced_loss_df.plot('Epoch', y=['Classification Loss', 'Regression Loss', 'Running Loss']) 

reduced_loss_df.plot('Epoch', y=['Running Loss'])<jupyter_output><empty_output><jupyter_text>Comparing 2 models to each other<jupyter_code>models = ['9.2_Model1', '9.2_Model2', '9.2_Model3', 
          '9.2_Model4'] 
#['8.23_Model2', '8.23_Model3', '8.25_Model1', '8.26_Model1', '9.2_Model1', '9.2_Model2', '9.2_Model3', 
#          '9.2_Model4'] 

val = {} 
train = {} 
for model in models: 
    val[model], train[model] = getDataframes(model) 


fig, ax = plt.subplots() 
for model in models: 
    val[model].plot('Epoch', 'Overall', ax=ax, label=model) 
    
    
fig2, ax2 = plt.subplots() 
for model in models: 
    train[model].plot('Epoch', 'Overall', ax=ax2, label=model)
fields = ['Overall', 'bovie', 'scalpel', 'forceps', 'needledriver'] 

for field in fields: 
    fig, ax = plt.subplots() 
    fig2, ax2 = plt.subplots() 
    for model in models: 
        val[model].plot('Epoch', field, ax=ax, label='{} {} Val'.format(model, field)) 
        train[model].plot('Epoch', field, ax=ax2, label='{} {} Train'.format(model, field))
    
    
 

loss = {} 
for model in models: 
    loss[model] = getReducedLossDataframe(model) 
    

fig, ax = plt.subplots() 
for model in models: 
    loss[model].plot('Epoch', 'Running Loss', ax=ax, label=model)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15627850410459107, 'fraction_numerical': 0.016114320462146548, 'mean_word_length': 4.306451612903226, 'pattern_counts': {'":': 1, '<': 13, '<?xml version=': 0, '>': 14, 'https://': 0, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '96964', 'license': 'MIT', 'n_tokens_mistral': 1248, 'n_tokens_neox': 1178, 'n_words': 236, 'path': 'MULTITASK_FILES/RETINANET_FILES/src/pytorch-retinanet/plots_eval.ipynb', 'repo_name': 'egoodman92/semi-supervised-surgery', 'size': '3289'}