<jupyter_start><jupyter_text>Import data<jupyter_code>data_dir = "data/UCM.tfrecords"

# Define the features in the TFRecords file
features = {
    "image_raw": tf.io.FixedLenSequenceFeature(
        [], dtype=tf.float32, allow_missing=True
    ),
    "height": tf.io.FixedLenFeature([], tf.int64),
    "width": tf.io.FixedLenFeature([], tf.int64),
    "channels": tf.io.FixedLenFeature([], tf.int64),
    "label": tf.io.FixedLenFeature([], tf.int64),
}

def parse_example(example_proto):
    image_features = tf.io.parse_single_example(example_proto, features)
    
    height = tf.cast(image_features["height"], tf.int32)
    width = tf.cast(image_features["width"], tf.int32)
    channels = tf.cast(image_features["channels"], tf.int32)
    
    image_raw = tf.reshape(
        tf.squeeze(image_features["image_raw"]),
        tf.stack([height, width, channels])
    )
    
    target = image_features["label"]
    
    return image_raw, target

with open('data/label_dict.pkl', 'rb') as f:
    label_dict = pkl.load(f)
    
tfdata = tf.data.TFRecordDataset(data_dir).map(parse_example, num_parallel_calls=tf.data.experimental.AUTOTUNE)

data_numpy = np.stack([x[0] for x in list(tfdata.as_numpy_iterator())]) #Could change this to not load whole dataset into memory if too big
labels = np.stack([x[1] for x in list(tfdata.as_numpy_iterator())])

num_images = data_numpy.shape[0]
image_size = data_numpy.shape[1]
no_channels = data_numpy.shape[3]
%%time
results_dict = {}

for model_name in filter(lambda s:s.startswith('UnsupervisedFeatureLearning'), os.listdir('.')):
    model_results = evaluate_model(model_name, data_numpy, labels, seed=1)
    results_dict = {**results_dict, **model_results}
    
df = pd.DataFrame.from_dict(results_dict, orient='index', columns=['accuracy', 'accuracy_std', 'accuracy_min (mean)', 'accuracy_min (min)', 'accuracy_max (mean)', 'accuracy_max (max)', 'f1_micro_std', 'f1_weighted', 'f1_min (mean)', 'f1_min (min)', 'f1_max (mean)', 'f1_max (max)'])
df.to_excel('Results_{}.xlsx'.format(time.strftime("%Y%m%d-%H%M%S")))<jupyter_output>WARNING:tensorflow:No training configuration found in save file, so the model was *not* compiled. Compile it manually.
{'fraction_non_alphanumeric': 0.1551094890510949, 'fraction_numerical': 0.012773722627737226, 'mean_word_length': 5.125698324022347, 'pattern_counts': {'":': 5, '<': 4, '<?xml version=': 0, '>': 4, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '635793', 'license': 'RSA-MD', 'n_tokens_mistral': 793, 'n_tokens_neox': 781, 'n_words': 148, 'path': 'settlement_segmentation/liunsupervised/parameter_selection.ipynb', 'repo_name': 'ai4er-cdt/gtc-exposure', 'size': '2192'}