Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MO] Remove USRNet until they publish license #261

Merged
merged 1 commit into from
Dec 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .ci/azure/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ jobs:
python3 -m pip install -U setuptools==51.0.0
python3 -m pip install -r requirements.txt
python3 -m pip install -r $(OPENVINO_REPO_DIR)/model-optimizer/requirements_onnx.txt
git clone https://github.com/cszn/USRNet && cd USRNet && git checkout 9564ad2 && cd ..
git clone https://github.com/CBICA/BrainMaGe && cd BrainMaGe && git checkout f188d94d8a44e23927b40ad11b311c97f26457a0 && python3 -m pip install . && cd ..
workingDirectory: $(REPO_DIR)/modules/mo_pytorch/test
displayName: 'Install PyTorch tests dependencies'
Expand Down
57 changes: 0 additions & 57 deletions modules/mo_pytorch/test/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,63 +236,6 @@ def test_rugpt3(self):
diff = np.max(np.abs(out - ref))
self.assertLessEqual(diff, 1e-4)

@unittest.skipIf(version.parse(torch.__version__) >= version.parse('1.8.0'), 'Deprecated FFT')
def test_usrnet(self):
sys.path.append('USRNet')
from models.network_usrnet import USRNet as net # for pytorch version <= 1.7.1
from utils import utils_deblur
from utils import utils_sisr as sr
from utils import utils_image as util

np.random.seed(324)
torch.manual_seed(32)
inp = np.random.standard_normal([1, 3, 56, 112]).astype(np.float32)
sf = 4

# source: https://github.com/cszn/USRNet/blob/master/main_test_realapplication.py
def get_kernel_sigma():
noise_level_img = 2 # noise level for LR image, 0.5~3 for clean images
kernel_width_default_x1234 = [0.4, 0.7, 1.5, 2.0] # default Gaussian kernel widths of clean/sharp images for x1, x2, x3, x4

noise_level_model = noise_level_img/255. # noise level of model
kernel_width = kernel_width_default_x1234[sf-1]

k = utils_deblur.fspecial('gaussian', 25, kernel_width)
k = sr.shift_pixel(k, sf) # shift the kernel
k /= np.sum(k)
kernel = util.single2tensor4(k[..., np.newaxis])
sigma = torch.tensor(noise_level_model).float().view([1, 1, 1, 1])

return kernel, sigma

kernel, sigma = get_kernel_sigma()

model = net(n_iter=8, h_nc=64, in_nc=4, out_nc=3, nc=[64, 128, 256, 512],
nb=2, act_mode="R", downsample_mode='strideconv', upsample_mode="convtranspose")
model.eval()

ref = model(torch.tensor(inp), kernel, sf, sigma)

# Forward random input through the model to check that nothing got stuck from reference data
dummy_inp = torch.randn(inp.shape)
dummy_kernel = torch.randn(kernel.shape)
dummy_sigma = torch.randn(sigma.shape)
model(dummy_inp, dummy_kernel, sf, dummy_sigma)

# Generate OpenVINO IR
mo_pytorch.convert(model, input_shape='[1, 3, 56, 112],[1, 1, 25, 25],[1, 1, 1, 1],[1]',
input='x{f32},k{f32},sigma{f32},sf{f32}->4',
model_name='model')

# Run model with OpenVINO and compare outputs
net = self.ie.read_network('model.xml')
exec_net = self.ie.load_network(net, 'CPU')
out = exec_net.infer({'x': inp, 'k': kernel, 'sigma': sigma})
out = next(iter(out.values()))

diff = np.max(np.abs(ref.detach().numpy() - out))
self.assertLessEqual(diff, 1e-4)


def test_mask_rcnn(self):
# For better efficiency, you may reduce parameters <box_detections_per_img> (default 100)
Expand Down