Subir archivos a "scripts_python"

This commit is contained in:
2026-08-18 08:01:28 +02:00
parent 6dec9330c4
commit 4601a2d6bb
5 changed files with 276 additions and 70 deletions
+7 -11
View File
@@ -9,8 +9,8 @@ from sklearn.cluster import KMeans
import torch.nn.functional as F
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
IMG_DIR = os.path.join(BASE_DIR, "..", "datos_para_ai")
ENCODER_PATH = os.path.join(BASE_DIR, "..", "models", "msi_encoder_trained.pth")
IMG_DIR = os.path.join(BASE_DIR, "..", "..", "outputs", "ion_images")
ENCODER_PATH = os.path.join(BASE_DIR, "..", "..", "outputs", "models", "msi_encoder_trained.pth")
DEVICE = torch.device("cuda" if torch.cuda.is_available() else "cpu")
class MSI_Structural_Encoder(nn.Module):
@@ -46,28 +46,24 @@ def load_encoder_diagnostic(path):
if __name__ == "__main__":
encoder = load_encoder_diagnostic(ENCODER_PATH)
# Load targets directly to test raw alignment
img_155 = os.path.join(IMG_DIR, "ion_155.75.png")
img_156 = os.path.join(IMG_DIR, "ion_156.07.png")
transform = transforms.Compose([
transforms.Resize((256, 256)),
transforms.ToTensor()
])
if os.path.exists(img_155) and os.path.exists(img_156):
# Convert to Grayscale "L"
t_155 = transform(Image.open(img_155).convert("L")).unsqueeze(0).to(DEVICE)
t_156 = transform(Image.open(img_156).convert("L")).unsqueeze(0).to(DEVICE)
with torch.no_grad():
f_155 = encoder(t_155)
f_156 = encoder(t_156)
# Check directional similarity
sim = F.cosine_similarity(f_155, f_156)
print(f"\n--- Feature Diagnostics ---")
print(f"Cosine Similarity between Vein Ions (155.75 vs 156.07): {sim.item():.4f}")
print("If this value is below 0.85, the loaded weight file is treating them as different shapes.")