Comments (3)
tmm_fast_torch is deprecated, I'll remove it with the next release. The Pytorch functionality is directly integrated into the coh_vec_tmm_disp_mstack function (terrible name, will change that in a future release, too). You can just pass either a torch.Tensor or a np.array to the function and it will compute with both.
from tmm_fast.
thanks! essentially I'm trying to reproduce the example from the Appendix 3 of your paper. I tried to replace tmm_fast_torch by coh_vec_tmm_disp_mstack, but I get an error (see below)
import numpy as np
import torch
from tmm_fast.vectorized_tmm_dispersive_multistack import coh_vec_tmm_disp_mstack as tmm
wl = np.linspace(500, 900, 301)*1e-9
theta = np.deg2rad(np.linspace(0, 90, 301))
n_layers = 12
stack_layers = np.random.uniform(20, 150, n_layers)*1e-9
stack_layers[0] = stack_layers[-1] = np.inf
optical_index = torch.tensor(np.random.uniform(1.2, 5, n_layers*len(wl)).reshape(1,n_layers,len(wl)))
optical_index[0,-1,0] = 1
stack_layers = torch.tensor(stack_layers.reshape(1,n_layers), requires_grad=True)
wl = torch.tensor(wl)
theta = torch.tensor(theta)
result = tmm('s', optical_index, stack_layers, theta, wl)['R']
mse = torch.nn.MSELoss()
error = mse(result, torch.zeros_like(result))
error.backward()
Nb: different from the function in the paper, the coh_vec_tmm_disp_mstack function accepts either numpy arrays or torch tensors. that's the reason for the conversion in my version of the code
this is the error I get:
Exception has occurred: RuntimeError
one of the variables needed for gradient computation has been modified by an inplace operation: [torch.DoubleTensor [1, 301, 301, 12]], which is output 0 of AsStridedBackward0, is at version 1; expected version 0 instead. Hint: the backtrace further above shows the operation that failed to compute its gradient. The variable in question was changed in there or anywhere later. Good luck!
File "G:\My Drive\05_Other_projects\04_filters\test2.py", line 29, in <module>
error.backward()
RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation: [torch.DoubleTensor [1, 301, 301, 12]], which is output 0 of AsStridedBackward0, is at version 1; expected version 0 instead. Hint: the backtrace further above shows the operation that failed to compute its gradient. The variable in question was changed in there or anywhere later. Good luck!
thanks for your help!
from tmm_fast.
Hey, I think the problem was in how the clamping was done with the delta function. I published a new release an PyPi (v0.2.1) with some minor bugfixes, this should also fix the problem you're encountering (It worked for me at least).
Btw, you can now directly do
from tmm_fast import coh_tmm
instead of the unwieldy vectorized_tmm_dispersive_multistack
from tmm_fast.
Related Issues (16)
- Error when dealing with absorbing material HOT 6
- Move from gym to gymnasium
- Request: Provide tmm_fast package via conda-forge HOT 1
- Provide tmm_fast via conda-forge HOT 3
- Implementation of an equivalent to tmm.tmm_core.inc_tmm() HOT 2
- Simplify dependencies HOT 1
- missing example.ipynb and quickstarter.py referenced in Readme HOT 1
- input datatype for inc_vec_tmm_disp_lstack HOT 1
- Use `api-array-compat` as a backend
- Calculation result different from tmm package
- Dataset generation example
- Nan will sometimes appear when calculating reflection coefficients HOT 2
- It works only with GPU HOT 1
- BUG: Unexpected squeezing of Theta and lambda_vacuum inputs in coh_vec_tmm_disp_mstack
- AttributeError: can't set attribute HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tmm_fast.