Spaces:
Sleeping
Sleeping
Commit
·
e3b1255
1
Parent(s):
b906063
Update
Browse files- backend/model_histo.py +31 -27
backend/model_histo.py
CHANGED
|
@@ -401,35 +401,39 @@ class BreastCancerClassifier:
|
|
| 401 |
batch = images[i:i + batch_size]
|
| 402 |
processed_batch = self.preprocess_image_batch(batch)
|
| 403 |
|
| 404 |
-
|
| 405 |
-
|
| 406 |
-
|
| 407 |
-
try:
|
| 408 |
-
# Handle different model interface types
|
| 409 |
-
if hasattr(self.path_foundation, 'signatures') and "serving_default" in self.path_foundation.signatures:
|
| 410 |
-
# TensorFlow SavedModel format
|
| 411 |
-
infer = self.path_foundation.signatures["serving_default"]
|
| 412 |
-
batch_embeddings = infer(tf.constant(processed_batch))
|
| 413 |
-
elif hasattr(self.path_foundation, 'predict'):
|
| 414 |
-
# Standard Keras model
|
| 415 |
-
batch_embeddings = self.path_foundation.predict(processed_batch, verbose=0)
|
| 416 |
-
else:
|
| 417 |
-
# Direct callable
|
| 418 |
-
batch_embeddings = self.path_foundation(processed_batch)
|
| 419 |
|
| 420 |
-
|
| 421 |
-
|
| 422 |
-
|
| 423 |
-
|
| 424 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 425 |
else:
|
| 426 |
-
|
| 427 |
-
|
| 428 |
-
|
| 429 |
-
|
| 430 |
-
|
| 431 |
-
|
| 432 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 433 |
print(f"Error processing batch {batch_num}: {e}")
|
| 434 |
continue
|
| 435 |
|
|
|
|
| 401 |
batch = images[i:i + batch_size]
|
| 402 |
processed_batch = self.preprocess_image_batch(batch)
|
| 403 |
|
| 404 |
+
# Calculate batch number before try block to ensure it's available in except block
|
| 405 |
+
batch_num = i // batch_size + 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 406 |
|
| 407 |
+
try:
|
| 408 |
+
# Handle different model interface types
|
| 409 |
+
if hasattr(self.path_foundation, 'signatures') and "serving_default" in self.path_foundation.signatures:
|
| 410 |
+
# TensorFlow SavedModel format
|
| 411 |
+
infer = self.path_foundation.signatures["serving_default"]
|
| 412 |
+
batch_embeddings = infer(tf.constant(processed_batch))
|
| 413 |
+
elif hasattr(self.path_foundation, 'predict'):
|
| 414 |
+
# Standard Keras model
|
| 415 |
+
batch_embeddings = self.path_foundation.predict(processed_batch, verbose=0)
|
| 416 |
else:
|
| 417 |
+
# Direct callable
|
| 418 |
+
batch_embeddings = self.path_foundation(processed_batch)
|
| 419 |
+
|
| 420 |
+
# Handle different output formats
|
| 421 |
+
if isinstance(batch_embeddings, dict):
|
| 422 |
+
key = list(batch_embeddings.keys())[0]
|
| 423 |
+
if hasattr(batch_embeddings[key], 'numpy'):
|
| 424 |
+
batch_embeddings = batch_embeddings[key].numpy()
|
| 425 |
+
else:
|
| 426 |
+
batch_embeddings = batch_embeddings[key]
|
| 427 |
+
elif hasattr(batch_embeddings, 'numpy'):
|
| 428 |
+
batch_embeddings = batch_embeddings.numpy()
|
| 429 |
+
|
| 430 |
+
embeddings.append(batch_embeddings)
|
| 431 |
+
|
| 432 |
+
# Progress reporting
|
| 433 |
+
if batch_num % 5 == 0:
|
| 434 |
+
print(f"Processed batch {batch_num}/{num_batches}")
|
| 435 |
+
|
| 436 |
+
except Exception as e:
|
| 437 |
print(f"Error processing batch {batch_num}: {e}")
|
| 438 |
continue
|
| 439 |
|