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
    • Branches
    • Releases
    • HEAD
    • refs/heads/linux-docker-colorization-net
    • refs/heads/master
    • 65e11ced75cba1fa4e3345b31cc159d631256bcf
    No releases to show
  • 7e96834
  • /
  • colorization_subnet
  • /
  • lib
  • /
  • TestDataset.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.

  • content
  • directory
  • revision
  • snapshot
origin badgecontent badge
swh:1:cnt:7d856d02e70d542ce9fb7577a5e5f89e26f16073
origin badgedirectory badge
swh:1:dir:30309eae4aa2195866bf672a0f3c1d1786f9d30a
origin badgerevision badge
swh:1:rev:65e11ced75cba1fa4e3345b31cc159d631256bcf
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.

  • content
  • directory
  • revision
  • 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
TestDataset.py
# Copyright (c) Microsoft. All rights reserved.

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

import torch.utils.data as data

from PIL import Image
import os
import struct
import os.path as osp
import numpy as np
import cv2

def parse_images(dir):
	dir = osp.expanduser(dir)
	image_pairs = []
	pair_file = osp.join(dir, 'pairs.txt')
	if osp.exists(pair_file):
		with open(pair_file, "r") as f:
			for line in f:
				pair = line.strip().split(" ")
				if len(pair) >=2 :
				    item0 = (pair[0], pair[1])
				    image_pairs.append(item0)
	else:
		raise (RuntimeError("Found no pair.txt in folder of: " + dir+ "\n"))
	return image_pairs

def pil_loader(path):
	with open(path, 'rb') as f:
		with Image.open(f) as img:
			return img.convert('RGB')

def combo5_loader(path, real_w, real_h):
	f = open(path, 'rb')

	# width, height
	d = f.read(4)
	im_sz = struct.unpack("i", d)
	h = im_sz[0]

	d = f.read(4)
	im_sz = struct.unpack("i", d)
	w = im_sz[0]

	# warp_ba_layer 4
	d = f.read(4)
	im_sz = struct.unpack("i", d)
	d = f.read(im_sz[0])
	file_bytes = np.asarray(bytearray(d), dtype=np.uint8)
	img_data_ndarray = cv2.imdecode(file_bytes, cv2.IMREAD_COLOR)
	img_data_ndarray = cv2.cvtColor(img_data_ndarray, cv2.COLOR_BGR2RGB)
	warp_ba = Image.fromarray(img_data_ndarray)

	# warp_aba_layer 4
	d = f.read(4)
	im_sz = struct.unpack("i", d)
	d = f.read(im_sz[0])
	file_bytes = np.asarray(bytearray(d), dtype=np.uint8)
	img_data_ndarray = cv2.imdecode(file_bytes, cv2.IMREAD_COLOR)
	img_data_ndarray = cv2.cvtColor(img_data_ndarray, cv2.COLOR_BGR2RGB)
	warp_aba = Image.fromarray(img_data_ndarray)

	# 5 layers: err_aba, err_ba, err_ab
	errs = []
	for l in range(5):
		d = f.read(4)
		im_sz = struct.unpack("i", d)
		d = f.read(im_sz[0])
		file_bytes = np.asarray(bytearray(d), dtype=np.uint8)
		img_data_ndarray = cv2.imdecode(file_bytes, cv2.IMREAD_GRAYSCALE)
		err_ba = Image.fromarray(img_data_ndarray)

		d = f.read(4)
		im_sz = struct.unpack("i", d)
		d = f.read(im_sz[0])
		file_bytes = np.asarray(bytearray(d), dtype=np.uint8)
		img_data_ndarray = cv2.imdecode(file_bytes, cv2.IMREAD_GRAYSCALE)
		err_ab = Image.fromarray(img_data_ndarray)
		errs.append([err_ba, err_ab])

	f.close()

	return errs, warp_ba, warp_aba


class TestDataset(data.Dataset):
	def __init__(self, data_root, transform=None):
		image_pairs = parse_images(data_root)
		if len(image_pairs) == 0:
			raise (RuntimeError("Found 0 image pairs in dataroot"))

		self.data_root = data_root
		self.image_pairs = image_pairs
		self.transform = transform

	def get_out_name(self, index):
		img_name0, img_name1 = self.image_pairs[index]
		out_name = '%s_%s.png' % (os.path.splitext(img_name0)[0], os.path.splitext(img_name1)[0])
		return out_name

	def __getitem__(self, index):
		image_id = 0
		pair_id = index

		image_names = ["", ""]
		image_names[0], image_names[1] = self.image_pairs[pair_id]

		image_path = osp.join(self.data_root, "input", image_names[image_id])
		image = pil_loader(image_path)

		inputs = [image, image]
		w, h = image.size

		image_comb_name = "%s_%s" % (os.path.splitext(image_names[image_id])[0], os.path.splitext(image_names[1 - image_id])[0])
		combo_path = osp.join(self.data_root, "combo_new", "%s.combo" % image_comb_name)
		errs, warp_ba, warp_aba = combo5_loader(combo_path, w, h)

		inputs.append(warp_ba)
		inputs.append(warp_aba)
		inputs = inputs + errs

		if self.transform is not None:
			inputs = self.transform(inputs)

		return inputs

	def __len__(self):
		return len(self.image_pairs)

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