Comments (17)
It seems working with torch now.
To write beam propagation function in pytorch, I used the functions in torch.fft module.
fftshift
function is newly added to pytorch (https://pytorch.org/docs/master/fft.html). So, I updated the torch to nightly version and updated the requirements file accordingly.
I have written the function in classical.py
under odak.learn
submodule. Basically, it was enough to replace the numpy functions with torch.
I also added a test script test_learn
which is very similar to test_beam_propagation
. In main
function, beam propagation with torch is used. In compare
function, I compared the results with propagating in numpy. Results seem close to each other up to 3 decimal points.
from odak.
About this specific line, from_numpy syntax can work with Numpy, however I am not sure if it can work with Cupy
. Perhaps it is a good idea to add a check as in below for making sure that it works both with Cupy
and Numpy
:
if np.__name__ == 'cupy':
sample_field = np.asnumpy(sample_field)
Same goes for other variables that may be effected from torch-cupy situation.
from odak.
@askaradeniz I would also suggest to have an another issue as a reminder to our selves for migrating to torch 1.8.0 in the future. I guess we can do that once it is a stable release.
I am keeping my promise and providing you a contributor access to this repository as well 👍 🥇
from odak.
It looks like they produce matrices that are transpose of each other. I made a small change at this line for this reason:
https://github.com/kunguz/odak/blob/2a7c900e49b37b8bf6ecd4e6ce785c40e06f5ea1/odak/wave/classical.py#L28
https://github.com/kunguz/odak/blob/2a7c900e49b37b8bf6ecd4e6ce785c40e06f5ea1/odak/learn/classical.py#L29
from odak.
I have added a new submodule named odak.learn
. It is supposed to be imported separately then the rest of the library as in below example.
import odak
import odak.learn
Note that once odak.learn
is imported, it also imports torch
. I have also added torch
to the requirements.txt as well.
We can initiate our effort for a beam propagator compiled in torch
using this file in the odak.learn
submodule.
from odak.
For now, it is a good idea to fork the repository as is. We can later merge the forked repository once you feel confident that you have a working beam propagator running in torch. Make sure you also have a working and verified test routine that can go under test
directory in the root.
If all goes well, I promise to grant you rights to this repository as a collaborator.
from odak.
Sounds awesome. Do you have a dedicated fork where you try these things or are you conducting such experiments in your local?
How should we move with this one? Shall I grant the collaborator access so that you can push it to the main branch. Or do you want me to merge the main branch with your fork? Please advise.
from odak.
I did the experiments with my own fork.
I opened a pull request for this feature. You can review and merge it into the main branch.
from odak.
I just saw your pull request. However, your version does not compile with travis CL, and I believe this is due to the requirements.txt
. The torch version you choose to set in that file is 1.8.0+dev...
. This isn't a major version, travis CL does not have that in it's stack of libraries, and we can not expect future users to rely on such a version. I believe torch has support for fft since 1.7.0, here is the documentation for that. May I ask of you to switch to that torch version and verify your code? Once this is verified, update your requirements.txt
with torch version 1.7.0
, and finally raise an another merge request.
from odak.
Probably, it is also a good idea to have the test routine named as test_learn_beam_propagation.py
as hopefully there will be more additions to the learn
submodule.
from odak.
Thank you for the review. I will make the necessary changes soon.
In pytorch 1.7.0, there is fft module but fftshift
, ifftshift
functions do not exist. There are implementations of these functions in neural-holography utilities. Can we use them?
from odak.
I believe so. But please let the authors know that you will be using a part of their implementations. Double check with the license of their repository and with them.
I would also suggest to have an another issue as a reminder to our selves for migrating to torch 1.8.0 in the future. I guess we can do that once it is a stable release.
from odak.
Once you brought fftshift
and ifftshift
, having them in a separate script named toolkit.py
in the learn
submodule also makes sense to me. What do you suggest in this case?
from odak.
I also think having a toolkit.py
script is a good idea. We may write additional utility functions for learn
there.
from odak.
Thanks!
from odak.
According to this issue torch.meshgrid
and numpy.meshgrid
behaves differently.
from odak.
Nicely done! It is good to be able to ditch transpose with this simple trick.
from odak.
Related Issues (20)
- Band-limited angular spectrum method HOT 16
- Double phase hologram method HOT 2
- Wide-window angular spectrum method for diffractionpropagation in far and near field HOT 1
- Adaptive-sampling angular spectrum method withfull utilization of space-bandwidth product HOT 1
- Fraunhofer beam propagation HOT 1
- Lens phase function generation HOT 2
- Pytorch and numpy/cupy comparison for beam propagation HOT 4
- Adding Stochastic Gradient Descent based hologram calculation HOT 2
- Thinning the dependencies HOT 5
- How to set up parallel computing HOT 1
- Dimensions fo quadratic phase function HOT 1
- Double Phase Encoding Implementation HOT 1
- [Feature Request] Add `.pre-commit-config.yml` HOT 3
- Gerchberg Saxton bug HOT 3
- Loading images with Odak in a normalized manner HOT 1
- Zero padding and cropping in beam propagation HOT 2
- Drawing multiple rays with visualize submodule.
- A question about calculating the pooling area in make_pooling_size_map_pixels HOT 2
- Wirtinger hologram generation routine HOT 1
- AttributeError: 'display_color_hvs' object has no attribute 'rgb_to_lms' HOT 2
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 odak.