Amould commited on
Commit
8ea732b
·
verified ·
1 Parent(s): 69d1aad

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -30
app.py CHANGED
@@ -3,47 +3,38 @@ import os
3
  os.system('pip3 install torch torchvision')# torchaudio')
4
 
5
  #pip3 install torch -q')
6
- import torch
7
  import sys
8
  import numpy as np
9
- from PIL import Image
10
- import itertools
11
- import glob
12
  import random
 
 
13
  import torch
14
- import torchvision
15
- import torchvision.transforms as transforms
16
- import torch.nn as nn
17
- import torch.optim as optim
18
- import torch.nn.functional as F
19
  from codes import *
20
 
21
- ## Print samples
22
 
23
- from torchvision.models import resnet18
 
 
24
 
 
 
 
 
25
 
26
- #device = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu")
27
- with_points = True
28
- dim = 128
29
- dim0 =224
30
- crop_ratio = dim/dim0
 
 
 
 
 
 
31
 
32
- file_savingfolder = './modelbest/'
33
- ext = '_bestVal'
34
- core_model_tst = resnet18(pretrained=True)
35
- core_model_tst.fc = Identity()
36
- core_model_tst.load_state_dict(torch.load(file_savingfolder+'core_model'+ext+'.pth', map_location=torch.device('cpu') ))
37
- #core_model_tst.to(device)
38
- IR_Model_tst = Build_IRmodel_Resnet(core_model_tst, registration_method)
39
- IR_Model_tst.load_state_dict(torch.load(file_savingfolder+'IR_Model'+ext+'.pth', map_location=torch.device('cpu')))
40
- #IR_Model_tst.to(device)
41
- IR_Model_tst.eval()
42
 
43
- def imgnt_reg(img1,img2):#, model_selected):
44
- #fixed_images = np.empty((1, 128, 128, 3))
45
- #moving_images = np.empty((1, 128, 128, 3))
46
- # prepare inputs:
47
  fixed_images = preprocess_image(img1, dim = 128)
48
  moving_images = preprocess_image(img2, dim = 128)
49
  M_i = torch.normal(torch.zeros([1,2,3]), torch.ones([1,2,3]))
 
3
  os.system('pip3 install torch torchvision')# torchaudio')
4
 
5
  #pip3 install torch -q')
 
6
  import sys
7
  import numpy as np
 
 
 
8
  import random
9
+ import matplotlib.pyplot as plt
10
+ import tqdm
11
  import torch
 
 
 
 
 
12
  from codes import *
13
 
 
14
 
15
+ #device = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu")
16
+ x_t,y_t = generate_standard_elips(N_samples = 30, a= 0.8,b = 1.5)
17
+ pointcloud_target = To_pointcloud(x_t,y_t)
18
 
19
+ dim = 1.5
20
+ RefRotation, Translation = random_rigid_transformation(dim=dim)
21
+ pointcloud_source = np.matmul(RefRotation, pointcloud_target.T).T + Translation
22
+ x_s, y_s, z_s = To_xyz(pointcloud_source)
23
 
24
+ PC1_mean = np.mean(pointcloud_source, axis=0)
25
+ pointcloud_source_norm = pointcloud_source - PC1_mean
26
+
27
+ PC2_mean = np.mean(pointcloud_target, axis=0)
28
+ pointcloud_target_norm = pointcloud_target - PC2_mean
29
+
30
+ x_sn, y_sn, z_sn = To_xyz(pointcloud_source_norm)
31
+ x_tn, y_tn, z_tn = To_xyz(pointcloud_target_norm)
32
+
33
+ pointcloud_source_norm_torch = torch.tensor(pointcloud_source_norm, requires_grad=False).to(torch.float32)
34
+ pointcloud_target_norm_torch = torch.tensor(pointcloud_target_norm, requires_grad=False).to(torch.float32)
35
 
 
 
 
 
 
 
 
 
 
 
36
 
37
+ def imgnt_reg(img1,img2):
 
 
 
38
  fixed_images = preprocess_image(img1, dim = 128)
39
  moving_images = preprocess_image(img2, dim = 128)
40
  M_i = torch.normal(torch.zeros([1,2,3]), torch.ones([1,2,3]))