Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

https://github.com/msracver/Deep-Exemplar-based-Colorization.git
31 March 2020, 07:21:55 UTC
  • Code
  • Branches (2)
  • Releases (0)
  • Visits
Revision 65e11ced75cba1fa4e3345b31cc159d631256bcf authored by Mingming He on 25 February 2020, 02:07:44 UTC, committed by GitHub on 25 February 2020, 02:07:44 UTC
Update README.md
Updated download links.
1 parent 4aacbcc
  • Files
  • Changes
    • Branches
    • Releases
    • HEAD
    • refs/heads/linux-docker-colorization-net
    • refs/heads/master
    • 65e11ced75cba1fa4e3345b31cc159d631256bcf
    No releases to show
  • 7e96834
  • /
  • colorization_subnet
  • /
  • test.py
Raw File Download Save again
Take a new snapshot of a software origin

If the archived software origin currently browsed is not synchronized with its upstream version (for instance when new commits have been issued), you can explicitly request Software Heritage to take a new snapshot of it.

Use the form below to proceed. Once a request has been submitted and accepted, it will be processed as soon as possible. You can then check its processing state by visiting this dedicated page.
swh spinner

Processing "take a new snapshot" request ...

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • revision
  • directory
  • content
  • snapshot
origin badgerevision badge
swh:1:rev:65e11ced75cba1fa4e3345b31cc159d631256bcf
origin badgedirectory badge
swh:1:dir:a43f8ae7c7d0bcda900357b7b10691a3b6faa7e3
origin badgecontent badge
swh:1:cnt:4c503a1dd44bae5f314462ff58e9f3bdd3628ef5
origin badgesnapshot badge
swh:1:snp:d5659e6cb6af2c54ee308f93eea62cc204d8ba45

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • revision
  • directory
  • content
  • snapshot
(requires biblatex-software package)
Generating citation ...
(requires biblatex-software package)
Generating citation ...
(requires biblatex-software package)
Generating citation ...
(requires biblatex-software package)
Generating citation ...
Tip revision: 65e11ced75cba1fa4e3345b31cc159d631256bcf authored by Mingming He on 25 February 2020, 02:07:44 UTC
Update README.md
Tip revision: 65e11ce
test.py
# Copyright (c) Microsoft. All rights reserved.

# Licensed under the MIT license. See LICENSE file in the project root for full license information.

if __name__ == '__main__':
    import os
    import argparse
    from PIL import Image
    import numpy as np
    import cv2

    import torch
    from torch.autograd import Variable
    from torch.utils.data import DataLoader

    from models.ExampleColorNet import ExampleColorNet

    from utils.util import mkdir_if_not, lab2rgb_transpose_mc

    from lib.TestDataset import TestDataset
    import lib.TestTransform as transforms

    parser = argparse.ArgumentParser()
    parser.add_argument('--data_root', default='', type=str)
    parser.add_argument('--test_model', type=str, default='models/example_net.pth')
    parser.add_argument('--gpu_id',type=int, default=0)
    parser.add_argument('--out_dir', type=str, default='output')
    parser.add_argument('--short_size', type=int, default=256)

    opt = parser.parse_args()
    mkdir_if_not(opt.out_dir)
    if opt.gpu_id >= 0:
        torch.cuda.set_device(opt.gpu_id)
    if opt.short_size > 0:
        test_dataset = TestDataset(opt.data_root,
                                   transform=transforms.Compose([transforms.Resize(opt.short_size),
                                                                 transforms.RGB2Lab(),
                                                                 transforms.ToTensor(),
                                                                 transforms.Normalize(),
                                                                 transforms.Concatenate()]))
    else:
        test_dataset = TestDataset(opt.data_root,
                                   transform=transforms.Compose([transforms.RGB2Lab(),
                                                                 transforms.ToTensor(),
                                                                 transforms.Normalize(),
                                                                 transforms.Concatenate()]))

    data_loader = DataLoader(test_dataset, batch_size=1, shuffle=False,
                             num_workers=1, pin_memory=True)

    color_net = ExampleColorNet(ic=13)
    assert os.path.exists(opt.test_model), 'cannot find the test model: %s ' % opt.test_model
    color_net.load_state_dict(torch.load(opt.test_model, map_location=lambda storage, loc: storage))
    color_net.eval()

    if opt.gpu_id >= 0:
        color_net.cuda()

    size_unit = 8
    for iter, data in enumerate(data_loader):
        orig_im_l, orig_err_ba, orig_warped_ba, orig_warped_aba, orig_im_ab, orig_err_ab = data
        out_name = test_dataset.get_out_name(iter)
        basename, ext = os.path.splitext(os.path.basename(out_name))
        print('testing for [%d/%d] %s ' % (iter, len(test_dataset), out_name))

        orig_h, orig_w = orig_im_l.size(2), orig_im_l.size(3)
        unit_h = int(orig_h/size_unit) * size_unit
        unit_w = int(orig_w/size_unit) * size_unit
        if unit_h != orig_h or unit_w != orig_w:
            im_l = torch.from_numpy(cv2.resize(orig_im_l[0].numpy().transpose((1,2,0)), (unit_w, unit_h))[np.newaxis,np.newaxis, ...])
            err_ba = torch.from_numpy(cv2.resize(orig_err_ba[0].numpy().transpose((1, 2, 0)), (unit_w, unit_h)).transpose((2, 0, 1))[np.newaxis, ...])
            warped_ba = torch.from_numpy(cv2.resize(orig_warped_ba[0].numpy().transpose((1, 2, 0)), (unit_w, unit_h)).transpose((2, 0, 1))[np.newaxis, ...])
            warped_aba = torch.from_numpy(cv2.resize(orig_warped_aba[0].numpy().transpose((1, 2, 0)), (unit_w, unit_h)).transpose((2, 0, 1))[np.newaxis, ...])
            im_ab = torch.from_numpy(cv2.resize(orig_im_ab[0].numpy().transpose((1, 2, 0)), (unit_w, unit_h)).transpose((2, 0, 1))[np.newaxis, ...])
            err_ab = torch.from_numpy(cv2.resize(orig_err_ab[0].numpy().transpose((1, 2, 0)), (unit_w, unit_h)).transpose((2, 0, 1))[np.newaxis, ...])
        else:
            im_l, err_ba, warped_ba, warped_aba, im_ab, err_ab = orig_im_l, orig_err_ba, orig_warped_ba, orig_warped_aba, orig_im_ab, orig_err_ab

        colornet_input = torch.cat((im_l, warped_ba[:, 1:, ...], err_ba, err_ab), dim=1)

        if opt.gpu_id >= 0:
            colornet_input_v = Variable(colornet_input.cuda())
        else:
            colornet_input_v = Variable(colornet_input)

        pred_ab_v = color_net(colornet_input_v)
        if unit_h != orig_h or unit_w != orig_w:
            pred_orig_ab = torch.from_numpy(cv2.resize(pred_ab_v.data[0].cpu().numpy().transpose((1, 2, 0)), (orig_w, orig_h), interpolation=cv2.INTER_CUBIC).transpose((2, 0, 1))[np.newaxis, ...])
        else:
            pred_orig_ab = pred_ab_v

        warpba_color_im = lab2rgb_transpose_mc(orig_im_l[0], pred_orig_ab[0])
        Image.fromarray(warpba_color_im).save(os.path.join(opt.out_dir, out_name))
The diff you're trying to view is too large. Only the first 1000 changed files have been loaded.
Showing with 0 additions and 0 deletions (0 / 0 diffs computed)
swh spinner

Computing file changes ...

back to top

Software Heritage — Copyright (C) 2015–2026, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Content policy— Contact— JavaScript license information— Web API