-
Notifications
You must be signed in to change notification settings - Fork 0
/
fdk.py
executable file
·41 lines (39 loc) · 1.8 KB
/
fdk.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import numpy as np
import torch
import os
os.chdir("/home/nv/wyk/inf-recon")
os.environ["CUDA_LAUNCH_BLOCKING"] = "1"
from ConeBeamLayers.BeijingGeometry import ForwardProjection
device = "cuda:3"
import ConeBeamLayers.BeijingGeometry as geometry
def getWater():
water = np.zeros([512,512], dtype="float32")
radius = 200
for x in range(512):
for y in range(512):
if(np.sqrt(np.square(x-256)+np.square(y-256))<radius):
water[x,y] = 1
r = np.zeros([1,1,64,512,512], dtype="float32")
r[...,:,:] = water
return r
if __name__ == '__main__':
# water_demo = torch.from_numpy(getWater()).to(device)
# water_demo.cpu().numpy().astype("float32").tofile("../Data/lz/water.raw")
# water_demo = torch.from_numpy(np.fromfile("../Data/aapm.raw", dtype="float32")).to(device)
# params = geometry.parameters
# geometry.parameters[12000:13000,3:6] += np.random.rand(1000,3)*40
# projection = ForwardProjection.apply(water_demo.reshape(1, 1,64,512,512)).reshape(1,1,1080*21,128,80).to(device)
# np.save("../Data/params.npy", geometry.parameters.detach().cpu().numpy())
# geometry.parameters = params
projection = np.fromfile("../Data/lz/100mA_abd_corr/projection.raw", dtype="float32")
projection = torch.from_numpy(projection).reshape(1,1,1080*21,128,80).to(device)
projection[torch.isnan(projection)] = 0
lossFunction = torch.nn.MSELoss()
output = torch.autograd.Variable(torch.zeros(64, 512, 512, dtype=torch.float32).to(device), requires_grad=True)
output_projection = ForwardProjection.apply(output.reshape(1, 1,64,512,512))
loss = lossFunction(projection, output_projection)
loss.backward()
fdkr = -output.grad.cpu().numpy().astype("float32")
fdkr[fdkr<0] = 0
fdkr /= fdkr.max()
fdkr.tofile("../Data/output.raw")