Comments (2)
I cannot get correct result from the python code, but when I use the command like
' autocolorize grayscale.png -o colorized.png' I get the correct resultsMy code is following:
import cv2
import os
import autocolorizepath2 = 'input/'
path3 = 'output/'
files= os.listdir(path2)classifier = autocolorize.load_default_classifier()
for ff in files:
gray_image = cv2.imread(path2+ff)
rgb_image = autocolorize.colorize(gray_image, classifier=classifier)
cv2.imwrite(path3+rgb_image,rgb_image)
How do you make out with it ?
from autocolorize.
You need to use the data reading and writing method in the code:
import cv2
import os
import autocolorize
import numpy as np
import torch
import time
from tqdm import tqdm
def load(path, dtype=np.float64):
"""
Loads an image from file.
Parameters
----------
path : str
Path to image file.
dtype : np.dtype
Defaults to ``np.float64``, which means the image will be returned as a
float with values between 0 and 1. If ``np.uint8`` is specified, the
values will be between 0 and 255 and no conversion cost will be
incurred.
"""
import skimage.io
im = skimage.io.imread(path)
if dtype == np.uint8:
return im
elif dtype in {np.float16, np.float32, np.float64}:
return im.astype(dtype) / 255
else:
raise ValueError('Unsupported dtype')
def save(path, im):
"""
Saves an image to file.
If the image is type float, it will assume to have values in [0, 1].
Parameters
----------
path : str
Path to which the image will be saved.
im : ndarray (image)
Image.
"""
from PIL import Image
if im.dtype == np.uint8:
pil_im = Image.fromarray(im)
else:
pil_im = Image.fromarray((im * 255).astype(np.uint8))
pil_im.save(path)
path2 = '/home/rpf/tgp/Colorization/colorization_valset/celebahq_val_256/'
path3 = '/home/rpf/tgp/Colorization/colorization_valset/celebahq_val_256_results/'
files = os.listdir(path2)
import caffe
caffe.set_mode_gpu()
classifier = autocolorize.load_default_classifier()
time_costs = []
skip = 5
for ff in tqdm(files):
skip -= 1
gray_image = load(path2 + ff)
# torch.cuda.synchronize()
start = time.time()
rgb_image = autocolorize.colorize(gray_image, classifier=classifier)
# torch.cuda.synchronize()
end = time.time()
cost = (end - start) * 1000
if skip < 0:
time_costs.append(cost)
save(path3 + ff, rgb_image)
print(np.average(time_costs))
from autocolorize.
Related Issues (20)
- Same problem as #8 when running autocolorize HOT 2
- Killed HOT 1
- difference in autocolorize.prototxt and train_vgg16.prototxt
- caffe compilation failed HOT 3
- Command for running HOT 1
- Where is the caffe.proto file ? HOT 1
- Fails with caffe-cpu
- Install failed "python setup.py egg_info"
- RuntimeError or AttributeError HOT 1
- calc_rgb param argument splitting HOT 2
- Pip package broken: missing caffee
- pre-trained model
- Missing demo files
- Training model on custom dataset HOT 1
- installing dependencies HOT 1
- Training - missing bgr_to_hsv_layer.hpp HOT 7
- Training - ExtendedImageDataLayer has no member named βiterβ HOT 3
- Error running for a single image HOT 7
- Unable to train from scratch HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from autocolorize.