import pickle # Define the path to your pickle file file_path = 'class_indices.pkl' try: # Open the file in binary read mode ('rb') with open(file_path, 'rb') as f: # Load the data from the file class_indices = pickle.load(f) # The number of classes is the length of the dictionary/list num_classes = len(class_indices) print(f"✅ Found {num_classes} classes in '{file_path}'.") # Optional: Print the first 5 class mappings to see what they look like if isinstance(class_indices, dict): print("\nHere are a few examples:") for i, (class_name, index) in enumerate(class_indices.items()): if i >= 5: break print(f" - '{class_name}': {index}") except FileNotFoundError: print(f"❌ Error: The file '{file_path}' was not found.") except Exception as e: print(f"An error occurred: {e}")