Spaces:
Sleeping
Sleeping
Commit ·
e3b1255
1
Parent(s): b906063
Update
Browse files400 unmodified lines401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435400 unmodified linesbatch = images[i:i + batch_size]processed_batch = self.preprocess_image_batch(batch)# Calculate batch number before try block to ensure it's available in except blockbatch_num = i // batch_size + 1try:# Handle different model interface typesif hasattr(self.path_foundation, 'signatures') and "serving_default" in self.path_foundation.signatures:# TensorFlow SavedModel formatinfer = self.path_foundation.signatures["serving_default"]batch_embeddings = infer(tf.constant(processed_batch))elif hasattr(self.path_foundation, 'predict'):# Standard Keras modelbatch_embeddings = self.path_foundation.predict(processed_batch, verbose=0)else:# Direct callablebatch_embeddings = self.path_foundation(processed_batch)# Handle different output formatsif isinstance(batch_embeddings, dict):key = list(batch_embeddings.keys())[0]if hasattr(batch_embeddings[key], 'numpy'):batch_embeddings = batch_embeddings[key].numpy()else:batch_embeddings = batch_embeddings[key]elif hasattr(batch_embeddings, 'numpy'):batch_embeddings = batch_embeddings.numpy()embeddings.append(batch_embeddings)# Progress reportingprint(f"Error processing batch {batch_num}: {e}")continue400 unmodified lines401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439400 unmodified linesbatch = images[i:i + batch_size]processed_batch = self.preprocess_image_batch(batch)# Calculate batch number before try block to ensure it's available in except blockbatch_num = i // batch_size + 1try:# Handle different model interface typesif hasattr(self.path_foundation, 'signatures') and "serving_default" in self.path_foundation.signatures:# TensorFlow SavedModel formatinfer = self.path_foundation.signatures["serving_default"]batch_embeddings = infer(tf.constant(processed_batch))elif hasattr(self.path_foundation, 'predict'):# Standard Keras modelbatch_embeddings = self.path_foundation.predict(processed_batch, verbose=0)else:# Direct callablebatch_embeddings = self.path_foundation(processed_batch)# Handle different output formatsif isinstance(batch_embeddings, dict):key = list(batch_embeddings.keys())[0]if hasattr(batch_embeddings[key], 'numpy'):batch_embeddings = batch_embeddings[key].numpy()else:batch_embeddings = batch_embeddings[key]elif hasattr(batch_embeddings, 'numpy'):batch_embeddings = batch_embeddings.numpy()embeddings.append(batch_embeddings)# Progress reportingif batch_num % 5 == 0:print(f"Processed batch {batch_num}/{num_batches}")except Exception as e:print(f"Error processing batch {batch_num}: {e}")continue
backend/model_histo.py+31-27