ttharden / Keyframe-Extraction-for-video-summarization

19 stars 3 forks source link

UnboundLocalError: local variable 'best_centers' referenced before assignment #4

Open isabel-07 opened 3 days ago

isabel-07 commented 3 days ago

I was trying to run the Keyframe_extraction.py file, but I got this error as it was initialising the center. It had worked fine with other videos I had tested it with, so I'm not sure why there would now be a problem with the 'best_centers' variable. Looking at the Kmeans_improvment code, I see that the variable is given a value inside if avg_silhouette > best_avg_silhouette, but there's not the if not choice in the code. I'm guessing one would always expect the avg_silhouette to always be bigger than the best_avg_silhouette, so I don't know what to do with this error.

0 2

['0', '2'] 3 229

['3', '229'] In the process of initialising the center Traceback (most recent call last): File "test_Keyframe_extraction.py", line 61, in scen_keyframe_extraction(scenes_path, features_path, video_path, save_path, folder_path) File "test_Keyframe_extraction.py", line 38, in scen_keyframe_extraction best_labels, best_centers, k, index = kmeans_silhouette(sub_features) File "/Keyframe-Extraction-for-video-summarization/src/extraction/Kmeans_improvment.py", line 81, in kmeans_silhouette return best_clusters, best_centers, best_k, center_indices UnboundLocalError: local variable 'best_centers' referenced before assignment

isabel-07 commented 3 days ago

I realized the problem was that the first segment was until 2, which means that the k in Kmeans_improvement would never be larger than 2, so it couldn't even enter the while loop. I modified the code to just ignore the first segment