https://github.com/lebellig/dim-checker
https://github.com/lebellig/dim-checker
Last synced: 11 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/lebellig/dim-checker
- Owner: lebellig
- License: mit
- Created: 2022-10-19T13:33:10.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2022-11-29T14:47:30.000Z (over 3 years ago)
- Last Synced: 2025-02-22T12:30:37.879Z (over 1 year ago)
- Language: Python
- Size: 45.9 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# DimChecker
Useful tool for functions, neural networks, or callable objects outputs dimensions checking. It allows fast testing and relies on pattern string for easy use.
```python
DimChecker().test_dims(nn, "bcl->bn(2*c+1)l", n=16)
```
## Define Pattern
### Write pattern
A pattern is defined as two formulas separated by an arrow:
```python
pattern = "bcl -> b(2*c)l"
DimChecker().test_dims(nn, pattern)
```
On the left side of the arrow we have the _inputs formula_ and the _outputs formula_ on the right.
```python
in_formula = "bcl"
out_formula = "b(2*c)l"
pattern = in_formula + "->" + out_formula
DimChecker().test_dims(nn, pattern)
```
### Write formulas
#### simple case
Dimensions are defined by a single letter. Here a common machine learning input tensor of shape $\textit{Batch} \times \textit{Channel} \times \textit{Length}$ :
```python
formula = "bcl"
```
For 2D images of shape $\textit{Batch} \times \textit{Channel} \times \textit{Height} \times \textit{Width}$ we may use:
```python
formula = "bchw"
```
#### arithmetical expression
#### several inputs or outputs
To use several inputs or outputs we only need to separate them by commas:
```python
# several inputs
pattern = "bcl, bl -> bcl"
# several outputs
pattern = "bcl -> bcl, bl"
# several inputs or outputs
pattern = "bcl, bc ->bcl, bl"
DimChecker().test_dims(nn, pattern)
```
## Add Constraints