<jupyter_start><jupyter_text>Load list of example videos<jupyter_code>cfr_data_root = os.path.normpath('/mnt/obi0/andreas/data/cfr')
predict_dir = os.path.join(cfr_data_root, 'predictions_echodata','FirstEchoEvents2repeat')
model = 'cfr_a4c_dgx-1_fc1_global_cfr_calc'
predict_file = os.path.join(predict_dir, 'cfr_models_30fps', model+'.parquet')
predict_df = pd.read_parquet(predict_file)
echo_df = predict_df[predict_df['model_name']==model]
display(echo_df.head(2))
# pick 10 random videos
n_videos=10
np.random.seed(123)
file_list = np.random.choice(echo_df['filename'].unique(), size=n_videos, replace=False)
file_list = [os.path.join(echo_df[echo_df['filename']==file]['dir'].values[0], file) for file in file_list]

def parameter_list(echo_df, file_list, video_attribute):
    video_attribute_list = [echo_df[echo_df['filename']==os.path.basename(file)][video_attribute].values[0] \
                            for file in file_list]
    print(f'{len(video_attribute_list)} values for attribute {video_attribute} found.')
    return video_attribute_list

deltaX_list = parameter_list(echo_df=echo_df, file_list=file_list, video_attribute='deltaX')
deltaY_list = parameter_list(echo_df=echo_df, file_list=file_list, video_attribute='deltaY')
frame_time_list = parameter_list(echo_df=echo_df, file_list=file_list, video_attribute='frame_time')
VC = Videoconverter(max_frame_time_ms=None, min_frames=None, meta_df=None)
npy_array_list = [VC.load_video(file) for file in file_list]
print(f'{len(npy_array_list)} videos loaded.')<jupyter_output>10 values for attribute deltaX found.
10 values for attribute deltaY found.
10 values for attribute frame_time found.
10 videos loaded.<jupyter_text>Models and weights<jupyter_code>checkpoint_dir = os.path.normpath('/mnt/obi0/andreas/data/cfr/checkpoints')
model_output_list = ['global_cfr_calc', 'rest_global_mbf', 'stress_global_mbf']
checkpoint_list = ['global_cfr.h5', 'rest_mbf_ammonia.h5', 'stress_mbf_ammonia.h5']
checkpoint_file_list = [os.path.join(checkpoint_dir, checkpoint_file) for checkpoint_file in checkpoint_list]
checkpoint_dict = dict(zip(model_output_list, checkpoint_file_list))
display(checkpoint_dict)<jupyter_output><empty_output><jupyter_text>Predictions from earlier run<jupyter_code>model_list = ['cfr_a4c_dgx-1_fc1_global_cfr_calc', 
              'mbf_ammonia_a4c_dgx-1_fc1_rest_global_mbf',
              'mbf_ammonia_a4c_dgx-1_fc1_stress_global_mbf']
pred_dict={}
for model in model_list:
    predict_file = os.path.join(predict_dir, 'cfr_models_30fps', model+'.parquet')
    predict_df = pd.read_parquet(predict_file, columns=['model_name', 'model_output', 'filename', 'predictions'])
    predict_df = predict_df[predict_df['model_name']==model]
    model_output = predict_df['model_output'].values[0]
    model_predictions = [predict_df[predict_df['filename']==os.path.basename(file)]['predictions'].values[0] for file in file_list]
    pred_dict_model = {model_output: model_predictions}
    pred_dict.update(pred_dict_model)
print(pred_dict.keys())<jupyter_output>dict_keys(['global_cfr_calc', 'rest_global_mbf', 'stress_global_mbf'])<jupyter_text>Predictions from video list and checkpoints<jupyter_code>qualified_index_list, predictions = runCFRModel(data_array_list=npy_array_list, 
                                                frame_time_ms_list=frame_time_list, 
                                                deltaX_list=deltaX_list, 
                                                deltaY_list=deltaY_list, 
                                                checkpoint_dict=checkpoint_dict,
                                                batch_size=1)
# Check the output
for model_output in checkpoint_dict.keys():
    df = pd.concat([pd.DataFrame(predictions[model_output]), pd.DataFrame(pred_dict[model_output])], axis=1)
    df.columns=['runCFRModel', 'earlier_predictions']
    display(df)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11340996168582375, 'fraction_numerical': 0.01123882503192848, 'mean_word_length': 5.14756671899529, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '488111', 'license': 'MIT', 'n_tokens_mistral': 1374, 'n_tokens_neox': 1334, 'n_words': 186, 'path': 'notebooks/testCFRModel.ipynb', 'repo_name': 'obi-ml-public/echoAI-PET-measurements', 'size': '3915'}