Use when after implementing a shared-weight ResNet18 encoder module but
Scanned 9/12/2026
Install to Claude Code
npx -y skills add HolobiomicsLab/asb-skill-collections --skill tensor-shape-validation-and-numerical-correctness-checking --agent claude-codeInstalls into .claude/skills of the current project.
Are you the author of Tensor Shape Validation And Numerical Correctness Checking?
Add the live security badge to your README — it updates automatically with every re-scan.
[](https://www.skillsdirectory.com/skills/holobiomicslab-tensor-shape-validation-and-numerical-correctness)More formats (shields.io, HTML) on the badges page.
---
name: tensor-shape-validation-and-numerical-correctness-checking
description: Use when after implementing a shared-weight ResNet18 encoder module but
before integrating it into the DeepION data augmentation and projection workflow.
license: CC-BY-4.0
metadata:
edam_operation: http://edamontology.org/operation_3438
edam_topics:
- http://edamontology.org/topic_0091
- http://edamontology.org/topic_3520
tools:
- ResNet18
- PyTorch
- TensorFlow
license_tier: restricted
provenance_tier: literature
derived_from:
- doi: 10.1021/acs.analchem.3c05002
title: deepion
evidence_spans:
- Two augmented images are propagated through a pair of ResNet18-based encoders
- Two augmented images are propagated through a pair of ResNet18-based encoders that
shared parameters
claims: []
provenance:
collection: https://w3id.org/holobiomicslab/asb-skill/collection/metabolomics/v2
assembled_by: scripts/collect_metabolomics_collection.py
sources:
- build: coll_deepion_cq
doi: 10.1021/acs.analchem.3c05002
title: deepion
dedup_kept_from: coll_deepion_cq
schema_version: 0.2.0
attribution:
generator: AgenticScienceBuilder
original_doi: 10.1021/acs.analchem.3c05002
all_source_dois:
- 10.1021/acs.analchem.3c05002
zenodo_doi: 10.5281/zenodo.20794027
curators: []
promoter: Louis-Félix Nothias
sponsor: CNRS & Université Côte d'Azur
---
# Tensor Shape Validation and Numerical Correctness Checking
> **License: restricted** — no clear open-source license detected for the underlying tool; verify licensing before commercial use or redistribution. <!-- asb-license-banner -->
## Summary
Verification step that confirms forward passes through a ResNet18-based encoder produce output tensors of expected shape (two 512-dimensional vectors) with numerically valid values before integration into the full DeepION contrastive learning pipeline. This prevents silent failures in representation learning that could compromise downstream ion image analysis.
## When to use
After implementing a shared-weight ResNet18 encoder module but before integrating it into the DeepION data augmentation and projection workflow. Use this skill when you have instantiated encoder logic that takes two augmented ion images as input and must confirm the output dimensionality and numerical properties match the pipeline's expectations (512-dimensional representation vectors per image).
## When NOT to use
- The encoder has not yet been instantiated or integrated into code; validation requires runnable forward logic.
- You are only reviewing architecture diagrams or pseudocode without executable model instances.
- The downstream task does not depend on exact dimensionality (though for DeepION, 512-dimensional vectors are essential to the projection and prediction modules).
## Inputs
- Two augmented ion images (typically as PyTorch tensors or TensorFlow arrays)
- Instantiated ResNet18 encoder model with shared parameters
- Expected output dimensionality specification (512)
## Outputs
- Boolean validation result (pass/fail) for shape correctness
- Boolean validation result for numerical validity (all finite values)
- Actual output tensor shapes and value ranges (for debugging)
## How to apply
Execute forward passes of two augmented ion images through the instantiated shared ResNet18 encoder and inspect the resulting tensors. Verify that each forward pass produces a single 512-dimensional vector (expected output shape [1, 512] or [512] depending on batch handling). Check that output values are finite (no NaNs or infinities) and within a reasonable numerical range for learned representations. Use PyTorch or TensorFlow's built-in shape inspection (`.shape` attribute) and numerical validity checks (`torch.isfinite()`, `tf.debugging.assert_all_finite()`). Compare actual shapes against the documented 512-dimensional specification. If shapes or numerical properties deviate, debug encoder architecture (final fully connected layer configuration, batch normalization behavior) before proceeding to loss computation.
## Related tools
- **ResNet18** (Backbone encoder architecture modified to output 512-dimensional representation vectors from two augmented ion images) — https://github.com/gankLei-X/DeepION
- **PyTorch** (Deep learning framework for instantiating the encoder, executing forward passes, and inspecting tensor shapes and numerical properties)
- **TensorFlow** (Alternative deep learning framework for instantiating and validating the encoder (equivalent to PyTorch))
## Examples
```
import torch
encoder = ResNet18(output_dim=512)
img1, img2 = torch.randn(1, 3, H, W), torch.randn(1, 3, H, W)
out1, out2 = encoder(img1), encoder(img2)
assert out1.shape == (1, 512) and out2.shape == (1, 512), f"Shape mismatch: {out1.shape}, {out2.shape}"
assert torch.isfinite(out1).all() and torch.isfinite(out2).all(), "NaN or Inf detected"
assert not torch.allclose(out1, out2), "Outputs are identical; check augmentation or encoder"
```
## Evaluation signals
- Output tensor shape from each forward pass exactly matches [1, 512] or [batch_size, 512] depending on batch configuration; no dimension mismatch.
- All output tensor values are finite (no NaN, inf, or -inf); `torch.isfinite(output).all()` or equivalent returns True.
- Two distinct forward passes through the shared encoder on different augmented images produce different numerical vectors (no frozen or collapsed representations).
- Output vector magnitudes or statistics fall within expected ranges for initialized neural networks (e.g., not all zeros or all maximum float values).
- Integration into the projection and prediction modules (downstream in the pipeline) proceeds without dimension-related runtime errors.
## Limitations
- Validation does not guarantee that the learned representations will be meaningful or that the contrastive loss will converge; it only confirms syntactic correctness.
- Shape validation is specific to the 512-dimensional specification for DeepION; other architectures or output dimensions require adjusted assertions.
- Numerical validity does not account for pathological cases such as gradient explosion or vanishing gradients during training, which may only manifest after multiple training iterations.
- Validation is performed on individual forward passes; it does not detect issues arising from parameter sharing semantics or backpropagation through shared weights.
## Evidence
- [other] Verify that forward passes of two augmented images produce two distinct 512-dimensional representation vectors from the shared encoder.: "Verify that forward passes of two augmented images produce two distinct 512-dimensional representation vectors from the shared encoder."
- [other] Validate the output tensor shapes and numerical correctness before integration into the full DeepION pipeline.: "Validate the output tensor shapes and numerical correctness before integration into the full DeepION pipeline."
- [readme] Two augmented images are propagated through a pair of ResNet18-based encoders that shared parameters, then output two 512-dimensional representation vectors: "Two augmented images are propagated through a pair of ResNet18-based encoders that shared parameters, then output two 512-dimensional representation vectors"
- [other] Configure the encoder to output 512-dimensional vectors by modifying the final fully connected layer.: "Configure the encoder to output 512-dimensional vectors by modifying the final fully connected layer."
Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.
No comments yet. Be the first to comment!