Thanks @ptrblck
The problem is that the statistical model required local libraries. So it’s not possible to have those libraries online.
But here is more detailed code:
device = torch.device(‘cuda’)
torch.manual_seed(0)
print(‘FITTING DEMO … (does not include pose or camera parameters)’)
print(’============’)
batch = 3

image_width = 224

image_height = 224
number_of_channels = 3
voxel_size = 2.0
view1_alpha = 0
view1_beta = -90
view2_alpha = -90
view2_beta = -90
number_of_channels = number_of_channels
transform = transforms.Compose([
transforms.ToPILImage(),
transforms.ToTensor(),
])
femur_ids = []
with open(‘data/femur_landmark_id.csv’, mode=‘r’) as inp:
reader = csv.reader(inp, delimiter=’,’)
for rows in reader:
femur_ids.append(int(float(rows[1])))
tibia_ids = []
with open(‘data/tibia_landmark_id.csv’, mode=‘r’) as inp:
reader = csv.reader(inp, delimiter=’,’)
for rows in reader:
tibia_ids.append(int(float(rows[1])))
carm = MobileCArm(source_to_detector_distance=40,
immersion_depth=0,
free_space=0,
sensor_height=200,
sensor_width=100)
dmfcModel = StatismoFileReaderDmfc.readDmfcModel(“data/models/kneeDmfc.h5”)
decoder = decoder = DecoderDmfc(dmfcModel,
carm,
first_view_alpha=view1_alpha,
first_view_beta=view1_beta,
second_view_alpha=view2_alpha,
second_view_beta=view2_beta,
number_of_channels=number_of_channels,
transform=transform,
voxel_size=voxel_size,
landmark_indices=[femur_ids, []]
).to(device=device)
tparam = []
for i in range(batch):
alpha = np.random.normal(np.zeros(1), 2.0, dmfcModel.feature_classes.variance.size)
tparam.append(alpha)
shape_parameters = torch.tensor(tparam, dtype=torch.float32, device=device)  # torch.randn([batch, dmfcModel.feature_classes.variance.size], dtype=torch.float32, device=device)
theta = shape_parameters
target_image, target_landmarks = decoder(theta)
param = []
for i in range(batch):
alpha = np.random.normal(np.zeros(1), 1.5 + 1.0 / (i + 1), dmfcModel.feature_classes.variance.size)
param.append(alpha)
shape_parameters_estimated = torch.tensor(param, dtype=torch.float32, device=device, requires_grad=True)

setup losses we use
loss = nn.MSELoss()
prior_loss = GaussianPrior()
lm_loss = LandmarkLoss()

setup (visual) reporting
report_interval = 1
fig, axs = pyplot.subplots(batch, 3)
print(‘LANDMARK FITTING … (not optimizing for color or light)’)
print(’================’)
learning_rate = 1
optimizer = torch.optim.Adagrad([
shape_parameters_estimated],
lr=learning_rate)
max_iter = 5
for iteration in range(max_iter):
theta_estimated = shape_parameters_estimated
fit_image, fit_landmarks = decoder(theta_estimated)



loss_lm = loss(target_landmarks, fit_landmarks)
print('fit land', fit_landmarks)
print('theta=', theta_estimated[0])

loss_value = loss_lm 

loss_value.backward()
optimizer.step()
optimizer.zero_grad()