Esempio n. 1
0
print('no frozen, no x_proj, no grad_proj, 2 param_groups')
test()
nfi.set_options(1, x_proj=x_proj, grad_proj=grad_proj)
print('set x_proj and grad_proj in param_group[1], 2 param_groups')
test()
nfi.add_param_group(param_group2)
print('add param_group')
test()
nfi.flat_param = random.randn(nfi.numel())
nfi.set_options(1, isfrozen=True)
print('set frozen in param_group[1], 3 param_groups')
test()
nfi.set_options(1, x_proj=None, grad_proj=None)
print('delete x_proj,grad_proj in param_group[1], 3 param_groups')
test()
nfi.set_options(0, x_proj=x_proj, grad_proj=grad_proj)
print('add x_proj and grad_proj in param_group[0], 3 param_groups')
test()
nfi.forward = forward_gen()
print('change forward function')
test()
nfi.flat_param = a0[:nfi.numel()] + 10
print('change flat_param')
print(nfi.forward() - nfi.f(a0[:nfi.numel()] + 10))
test()
nfi.set_options(1, isfrozen=False)
print('set free in param_group[1], 3 param_groups')
test()
#%%
Esempio n. 2
0
inputs_shape = [50, 50, 50]
IN, JN, KN = int(200 / inputs_shape[0]), int(200 / inputs_shape[1]), int(
    200 / inputs_shape[2])
indx = zeros((IN * JN * KN, 3), dtype=int32)
idx = 0
for i in range(IN):
    for j in range(JN):
        for k in range(KN):
            indx[idx] = array([i, j, k]) * array(inputs_shape)
            idx += 1
for i in range(64):
    inputs = dataset[indx[i, 0]:indx[i, 0] + inputs_shape[0],
                     indx[i, 1]:indx[i, 1] + inputs_shape[1],
                     indx[i, 2]:indx[i, 2] + inputs_shape[2]]
    inputs = inputs.clone()
    nfi.forward = lambda: I.forward(inputs)
    x = nfi.flat_param
    x, f, d = lbfgsb(nfi.f,
                     x,
                     nfi.fprime,
                     m=1000,
                     maxiter=20,
                     factr=1,
                     pgtol=1e-16,
                     iprint=10)
#%%
inputs = dataset[random.randint(200 / inputs_shape[0]) +
                 int(200 / inputs_shape[0]) *
                 arange(0, inputs_shape[0], dtype=int32)[:, newaxis, newaxis],
                 random.randint(200 / inputs_shape[1]) +
                 int(200 / inputs_shape[1]) *
Esempio n. 3
0
    for j in range(JN):
        for k in range(KN):
            indx[idx] = array([i,j,k])*array(inputs_shape)
            idx += 1
#%%
nfi = NumpyFunctionInterface([I.interp_coe,],forward=lambda :forward(I,dataset))
nfi.flat_param = random.randn(nfi.numel())
x0 = nfi.flat_param
for i in range(64):
    inputs = dataset[
            indx[i,0]:indx[i,0]+inputs_shape[0],
            indx[i,1]:indx[i,1]+inputs_shape[1],
            indx[i,2]:indx[i,2]+inputs_shape[2]
            ]
    inputs = inputs.clone()
    nfi.forward = lambda :forward(I,inputs)
    x = nfi.flat_param
    x,f,d = lbfgsb(nfi.f,x,nfi.fprime,m=1000,maxiter=20,factr=1,pgtol=1e-16,iprint=10)
#%%
outputs = IFixInputs()
outputs_true = torch.from_numpy(testfunc(IFixInputs.inputs.cpu().numpy()))
outputs_true = outputs_true.view(outputs.size())
outputs_true = outputs.data.new(outputs_true.size()).copy_(outputs_true)

nfi = NumpyFunctionInterface([IFixInputs.interp_coe,],forward=lambda :forwardFixInputs(IFixInputs,outputs_true))
nfi.flat_param = random.randn(nfi.numel())
for i in range(64):
    inputs = dataset[
            indx[i,0]:indx[i,0]+inputs_shape[0],
            indx[i,1]:indx[i,1]+inputs_shape[1],
            indx[i,2]:indx[i,2]+inputs_shape[2]