Comments (6)
Glad it worked for you! I'm going to close this issue, but feel free to reopen it or open a new one if something else comes up.
from leap.
Yes, batch mode is implemented in leaptorch.py. It is either executed as a part of a forward and backward pass or you can explicitly call it. Look at test_recon_NN.py. On lines 235 and 279 we have:
proj = Projector(forward_project=True, use_static=True, use_gpu=use_cuda, gpu_device=device)
and
g = proj(f)
The proj(f) does a batch forward projection, but if we would have done:
proj = Projector(forward_project=False, use_static=True, use_gpu=use_cuda, gpu_device=device)
then
f = proj(g)
would do batch backprojection (adjoint of forward projection)
from leap.
Hi Kyle,
Thank you so much. It looks we should set the "batch_size" to the desired value first, then we can use batch mode, which means it does not recognize the batch mode automatically? Second, is there a way to copy or clone the "Projector()" object? Otherwise, it seems we must set forward_project=False to call the backprojection, which seems inconvenient?
from leap.
Moreover, I used the following code to check the adjoint:
**
proj_im = proj(f)
yy = torch.randn_like(proj_im)
proj.forward_project=False
torch.sum(yy * proj_im)
torch.sum(proj(yy) * f)
**
but the values of torch.sum(yy * proj_im) and torch.sum(proj(yy) * f) are significantly different. Looks I used something is wrong. Could you help me to clarify this? Thanks.
from leap.
I'm not sure what you are trying to do, so maybe using leaptorch is just confusing. Below is some code that I think does what you need it to do.
import sys
import os
import time
import numpy as np
from leapctype import *
leapct = tomographicModels()
def project_batch(g_batch,f_batch):
for n in range(g_batch.shape[0]):
leapct.project(g_batch[n,:,:,:],f_batch[n,:,:,:])
return g_batch
def backproject_batch(g_batch,f_batch):
for n in range(g_batch.shape[0]):
leapct.backproject(g_batch[n,:,:,:],f_batch[n,:,:,:])
return f_batch
batch_size = 4
numCols = 512
numAngles = 2*2*int(360*numCols/1024)
pixelSize = 0.65*512/numCols
numRows = numCols//2
leapct.set_parallelbeam(numAngles=numAngles, numRows=numRows, numCols=numCols, pixelHeight=pixelSize*11.0/14.0, pixelWidth=pixelSize*11.0/14.0, centerRow=0.5*(numRows-1), centerCol=0.5*(numCols-1), phis=leapct.setAngleArray(numAngles, 360.0))
leapct.set_default_volume()
vol_dim1, vol_dim2, vol_dim3 = leapct.get_volume_dim()
proj_dim1, proj_dim2, proj_dim3 = leapct.get_projection_dim()
#device = torch.device("cuda:0")
vol_data = torch.from_numpy(np.zeros((batch_size, vol_dim1, vol_dim2, vol_dim3), dtype=np.float32))
proj_data = torch.from_numpy(np.zeros((batch_size, proj_dim1, proj_dim2, proj_dim3), dtype=np.float32))
vol_data = vol_data.float().to(torch.device("cuda:0"))
proj_data = proj_data.float().to(torch.device("cuda:0"))
f = leapct.allocate_volume()
g = leapct.allocate_projections()
leapct.set_FORBILD(f,True)
f = torch.from_numpy(f)
f = f.float().to(torch.device("cuda:0"))
vol_data[:,:,:,:] = f[None,:,:,:]
Bf = vol_data.clone()
project_batch(proj_data, vol_data)
yy = torch.randn_like(proj_data)
print(torch.sum(yy * proj_data))
print(torch.sum(backproject_batch(yy,Bf) * vol_data))
from leap.
Thank you so much. This works for me.
Actually, I want to train a NN solver but assume the forward model can be changed.
BTW, I personally think the batch mode is more efficient than the following implementation? (maybe I am wrong)
def project_batch(g_batch,f_batch):
for n in range(g_batch.shape[0]):
leapct.project(g_batch[n,:,:,:],f_batch[n,:,:,:])
return g_batch
because this projection used loop but the batch mode in PyTorch automatically calls the parallel computing?
from leap.
Related Issues (20)
- Remove the limitation of 5 degree aligned to z-axis HOT 5
- Issue with Helical Reconstruction Geometry Parameters in Leap HOT 9
- laminography zero recon slice issue HOT 3
- Incorrect number of voxels in helical geometry when angular range is bigger than 360 degrees HOT 1
- Laminography multiply factor to align the projection image to slice image HOT 9
- Out of Memory Error for 4000x4000x2096 VOLUME HOT 23
- Out boundary brightness issue HOT 2
- intensity shift of helical fbp HOT 12
- Projection image's intensity slope reverse issue HOT 12
- fail to backpropagate after proj.fbp HOT 9
- Phantom jig calibration supporting HOT 6
- Use Projector in a Nerual Network HOT 6
- display unblock HOT 2
- MLTR filters: IndexError: list index out of range HOT 3
- Question: cone beam to cone-parallel rebinning HOT 21
- sinogram order base back-projection supporting HOT 2
- tau param issue with convert_modularbeam() function HOT 2
- Force CPU reconstruction HOT 1
- Half-Fan Weighting Artifacts 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 leap.