Spaces:
Runtime error
Runtime error
stuff
Browse files- .gitattributes +1 -0
- .gitattributes copy +36 -0
- .gitignore +1 -0
- Dockerfile +18 -0
- README copy.md +11 -0
- colourize/__init__.py +0 -0
- colourize/asgi.py +16 -0
- colourize/settings.py +128 -0
- colourize/urls.py +23 -0
- colourize/wsgi.py +16 -0
- imageModel/__init__.py +0 -0
- imageModel/admin.py +3 -0
- imageModel/apps.py +6 -0
- imageModel/migrations/__init__.py +0 -0
- imageModel/models.py +3 -0
- imageModel/tests.py +3 -0
- imageModel/urls.py +7 -0
- imageModel/utils/main.py +60 -0
- imageModel/utils/models/colorization_deploy_v2.prototxt +589 -0
- imageModel/utils/models/colorization_release_v2.caffemodel +3 -0
- imageModel/utils/models/pts_in_hull.npy +3 -0
- imageModel/views.py +32 -0
- manage.py +22 -0
- requirements.txt +0 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
*.caffemodel filter=lfs diff=lfs merge=lfs -text
|
.gitattributes copy
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
| 13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
| 29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 32 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
| 33 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
*.caffemodel filter=lfs diff=lfs merge=lfs -text
|
.gitignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
**/__pycache__/**
|
Dockerfile
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.11
|
| 2 |
+
|
| 3 |
+
WORKDIR /code
|
| 4 |
+
|
| 5 |
+
COPY ./requirements.txt /code/requirements.txt
|
| 6 |
+
|
| 7 |
+
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
|
| 8 |
+
|
| 9 |
+
RUN useradd -m -u 1000 user
|
| 10 |
+
USER user
|
| 11 |
+
ENV HOME=/home/user \
|
| 12 |
+
PATH=/home/user/.local/bin:$PATH
|
| 13 |
+
|
| 14 |
+
WORKDIR $HOME/app
|
| 15 |
+
|
| 16 |
+
COPY --chown=user . $HOME/app
|
| 17 |
+
|
| 18 |
+
CMD ["python", "manage.py", "runserver", "0.0.0.0:7860"]
|
README copy.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: OpenCvColourize
|
| 3 |
+
emoji: 📚
|
| 4 |
+
colorFrom: red
|
| 5 |
+
colorTo: pink
|
| 6 |
+
sdk: docker
|
| 7 |
+
pinned: false
|
| 8 |
+
license: mit
|
| 9 |
+
---
|
| 10 |
+
|
| 11 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
colourize/__init__.py
ADDED
|
File without changes
|
colourize/asgi.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
ASGI config for colourize project.
|
| 3 |
+
|
| 4 |
+
It exposes the ASGI callable as a module-level variable named ``application``.
|
| 5 |
+
|
| 6 |
+
For more information on this file, see
|
| 7 |
+
https://docs.djangoproject.com/en/5.0/howto/deployment/asgi/
|
| 8 |
+
"""
|
| 9 |
+
|
| 10 |
+
import os
|
| 11 |
+
|
| 12 |
+
from django.core.asgi import get_asgi_application
|
| 13 |
+
|
| 14 |
+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'colourize.settings')
|
| 15 |
+
|
| 16 |
+
application = get_asgi_application()
|
colourize/settings.py
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Django settings for colourize project.
|
| 3 |
+
|
| 4 |
+
Generated by 'django-admin startproject' using Django 5.0.3.
|
| 5 |
+
|
| 6 |
+
For more information on this file, see
|
| 7 |
+
https://docs.djangoproject.com/en/5.0/topics/settings/
|
| 8 |
+
|
| 9 |
+
For the full list of settings and their values, see
|
| 10 |
+
https://docs.djangoproject.com/en/5.0/ref/settings/
|
| 11 |
+
"""
|
| 12 |
+
|
| 13 |
+
from pathlib import Path
|
| 14 |
+
|
| 15 |
+
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
| 16 |
+
BASE_DIR = Path(__file__).resolve().parent.parent
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
# Quick-start development settings - unsuitable for production
|
| 20 |
+
# See https://docs.djangoproject.com/en/5.0/howto/deployment/checklist/
|
| 21 |
+
|
| 22 |
+
# SECURITY WARNING: keep the secret key used in production secret!
|
| 23 |
+
SECRET_KEY = 'django-insecure-5^=_be4pw&9qxni5p!!2zd77#vo*5af1^5ppo)@nbt07of2lua'
|
| 24 |
+
|
| 25 |
+
# SECURITY WARNING: don't run with debug turned on in production!
|
| 26 |
+
DEBUG = True
|
| 27 |
+
|
| 28 |
+
ALLOWED_HOSTS = []
|
| 29 |
+
|
| 30 |
+
CORS_ALLOW_ALL_ORIGINS = True
|
| 31 |
+
|
| 32 |
+
# Application definition
|
| 33 |
+
|
| 34 |
+
INSTALLED_APPS = [
|
| 35 |
+
'django.contrib.admin',
|
| 36 |
+
'django.contrib.auth',
|
| 37 |
+
'django.contrib.contenttypes',
|
| 38 |
+
'django.contrib.sessions',
|
| 39 |
+
'django.contrib.messages',
|
| 40 |
+
'django.contrib.staticfiles',
|
| 41 |
+
'imageModel.apps.ImagemodelConfig',
|
| 42 |
+
'corsheaders',
|
| 43 |
+
'rest_framework',
|
| 44 |
+
]
|
| 45 |
+
|
| 46 |
+
MIDDLEWARE = [
|
| 47 |
+
'django.middleware.security.SecurityMiddleware',
|
| 48 |
+
'django.contrib.sessions.middleware.SessionMiddleware',
|
| 49 |
+
'corsheaders.middleware.CorsMiddleware',
|
| 50 |
+
'django.middleware.common.CommonMiddleware',
|
| 51 |
+
'django.middleware.csrf.CsrfViewMiddleware',
|
| 52 |
+
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
| 53 |
+
'django.contrib.messages.middleware.MessageMiddleware',
|
| 54 |
+
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
| 55 |
+
]
|
| 56 |
+
|
| 57 |
+
ROOT_URLCONF = 'colourize.urls'
|
| 58 |
+
|
| 59 |
+
TEMPLATES = [
|
| 60 |
+
{
|
| 61 |
+
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
| 62 |
+
'DIRS': [],
|
| 63 |
+
'APP_DIRS': True,
|
| 64 |
+
'OPTIONS': {
|
| 65 |
+
'context_processors': [
|
| 66 |
+
'django.template.context_processors.debug',
|
| 67 |
+
'django.template.context_processors.request',
|
| 68 |
+
'django.contrib.auth.context_processors.auth',
|
| 69 |
+
'django.contrib.messages.context_processors.messages',
|
| 70 |
+
],
|
| 71 |
+
},
|
| 72 |
+
},
|
| 73 |
+
]
|
| 74 |
+
|
| 75 |
+
WSGI_APPLICATION = 'colourize.wsgi.application'
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
# Database
|
| 79 |
+
# https://docs.djangoproject.com/en/5.0/ref/settings/#databases
|
| 80 |
+
|
| 81 |
+
DATABASES = {
|
| 82 |
+
'default': {
|
| 83 |
+
'ENGINE': 'django.db.backends.sqlite3',
|
| 84 |
+
'NAME': BASE_DIR / 'db.sqlite3',
|
| 85 |
+
}
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
# Password validation
|
| 90 |
+
# https://docs.djangoproject.com/en/5.0/ref/settings/#auth-password-validators
|
| 91 |
+
|
| 92 |
+
AUTH_PASSWORD_VALIDATORS = [
|
| 93 |
+
{
|
| 94 |
+
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
|
| 95 |
+
},
|
| 96 |
+
{
|
| 97 |
+
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
|
| 98 |
+
},
|
| 99 |
+
{
|
| 100 |
+
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
|
| 101 |
+
},
|
| 102 |
+
{
|
| 103 |
+
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
|
| 104 |
+
},
|
| 105 |
+
]
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
# Internationalization
|
| 109 |
+
# https://docs.djangoproject.com/en/5.0/topics/i18n/
|
| 110 |
+
|
| 111 |
+
LANGUAGE_CODE = 'en-us'
|
| 112 |
+
|
| 113 |
+
TIME_ZONE = 'UTC'
|
| 114 |
+
|
| 115 |
+
USE_I18N = True
|
| 116 |
+
|
| 117 |
+
USE_TZ = True
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
# Static files (CSS, JavaScript, Images)
|
| 121 |
+
# https://docs.djangoproject.com/en/5.0/howto/static-files/
|
| 122 |
+
|
| 123 |
+
STATIC_URL = 'static/'
|
| 124 |
+
|
| 125 |
+
# Default primary key field type
|
| 126 |
+
# https://docs.djangoproject.com/en/5.0/ref/settings/#default-auto-field
|
| 127 |
+
|
| 128 |
+
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
colourize/urls.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
URL configuration for colourize project.
|
| 3 |
+
|
| 4 |
+
The `urlpatterns` list routes URLs to views. For more information please see:
|
| 5 |
+
https://docs.djangoproject.com/en/5.0/topics/http/urls/
|
| 6 |
+
Examples:
|
| 7 |
+
Function views
|
| 8 |
+
1. Add an import: from my_app import views
|
| 9 |
+
2. Add a URL to urlpatterns: path('', views.home, name='home')
|
| 10 |
+
Class-based views
|
| 11 |
+
1. Add an import: from other_app.views import Home
|
| 12 |
+
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
|
| 13 |
+
Including another URLconf
|
| 14 |
+
1. Import the include() function: from django.urls import include, path
|
| 15 |
+
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
| 16 |
+
"""
|
| 17 |
+
from django.contrib import admin
|
| 18 |
+
from django.urls import path, include
|
| 19 |
+
|
| 20 |
+
urlpatterns = [
|
| 21 |
+
path('admin/', admin.site.urls),
|
| 22 |
+
path('api/', include('imageModel.urls', namespace='imageModel')),
|
| 23 |
+
]
|
colourize/wsgi.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
WSGI config for colourize project.
|
| 3 |
+
|
| 4 |
+
It exposes the WSGI callable as a module-level variable named ``application``.
|
| 5 |
+
|
| 6 |
+
For more information on this file, see
|
| 7 |
+
https://docs.djangoproject.com/en/5.0/howto/deployment/wsgi/
|
| 8 |
+
"""
|
| 9 |
+
|
| 10 |
+
import os
|
| 11 |
+
|
| 12 |
+
from django.core.wsgi import get_wsgi_application
|
| 13 |
+
|
| 14 |
+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'colourize.settings')
|
| 15 |
+
|
| 16 |
+
application = get_wsgi_application()
|
imageModel/__init__.py
ADDED
|
File without changes
|
imageModel/admin.py
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from django.contrib import admin
|
| 2 |
+
|
| 3 |
+
# Register your models here.
|
imageModel/apps.py
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from django.apps import AppConfig
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
class ImagemodelConfig(AppConfig):
|
| 5 |
+
default_auto_field = 'django.db.models.BigAutoField'
|
| 6 |
+
name = 'imageModel'
|
imageModel/migrations/__init__.py
ADDED
|
File without changes
|
imageModel/models.py
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from django.db import models
|
| 2 |
+
|
| 3 |
+
# Create your models here.
|
imageModel/tests.py
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from django.test import TestCase
|
| 2 |
+
|
| 3 |
+
# Create your tests here.
|
imageModel/urls.py
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from django.urls import path
|
| 2 |
+
from .views import ImageModelView
|
| 3 |
+
|
| 4 |
+
app_name='imageModel'
|
| 5 |
+
urlpatterns = [
|
| 6 |
+
path('colourize/', ImageModelView.as_view()),
|
| 7 |
+
]
|
imageModel/utils/main.py
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
import cv2
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
DIR = r"C:/Users/dilji/OneDrive/Documents/CodingFiles/codeInit/backend/imageModel/utils"
|
| 6 |
+
PROTOTEXT = os.path.join(DIR, r"models/colorization_deploy_v2.prototxt")
|
| 7 |
+
MODEL = os.path.join(DIR, r"models/colorization_release_v2.caffemodel")
|
| 8 |
+
POINTS = os.path.join(DIR, r"models/pts_in_hull.npy")
|
| 9 |
+
|
| 10 |
+
def colorize(image_path):
|
| 11 |
+
image_path = os.path.join(DIR, image_path)
|
| 12 |
+
print("[INFO] Loading model...")
|
| 13 |
+
net = cv2.dnn.readNetFromCaffe(prototxt=PROTOTEXT, caffeModel=MODEL)
|
| 14 |
+
pts = np.load(POINTS)
|
| 15 |
+
|
| 16 |
+
class8 = net.getLayerId("class8_ab")
|
| 17 |
+
conv8 = net.getLayerId("conv8_313_rh")
|
| 18 |
+
pts = pts.transpose().reshape(2, 313, 1, 1)
|
| 19 |
+
net.getLayer(class8).blobs = [pts.astype("float32")]
|
| 20 |
+
net.getLayer(conv8).blobs = [np.full([1, 313], 2.606, dtype="float32")]
|
| 21 |
+
|
| 22 |
+
print("[INFO] Loading image...")
|
| 23 |
+
image = cv2.imread(image_path)
|
| 24 |
+
scaled = image.astype("float32") / 255.0
|
| 25 |
+
lab = cv2.cvtColor(scaled, cv2.COLOR_BGR2LAB)
|
| 26 |
+
|
| 27 |
+
resized = cv2.resize(lab, (224, 224))
|
| 28 |
+
L = cv2.split(resized)[0]
|
| 29 |
+
L -= 50
|
| 30 |
+
|
| 31 |
+
print("[INFO] Colorizing image...")
|
| 32 |
+
net.setInput(cv2.dnn.blobFromImage(L))
|
| 33 |
+
ab = net.forward()[0, :, :, :].transpose((1, 2, 0))
|
| 34 |
+
ab = cv2.resize(ab, (image.shape[1], image.shape[0]))
|
| 35 |
+
L = cv2.split(lab)[0]
|
| 36 |
+
colorized = np.concatenate((L[:, :, np.newaxis], ab), axis=2)
|
| 37 |
+
colorized = cv2.cvtColor(colorized, cv2.COLOR_LAB2BGR)
|
| 38 |
+
colorized = np.clip(colorized, 0, 1)
|
| 39 |
+
|
| 40 |
+
colorized = (255*colorized)
|
| 41 |
+
colorized = colorized.astype(np.uint8)
|
| 42 |
+
|
| 43 |
+
cv2.imwrite(os.path.join(DIR, "colorized.jpg"), colorized)
|
| 44 |
+
return os.path.join(DIR, "colorized.jpg")
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
def save_image(image_data, path):
|
| 48 |
+
with open(os.path.join(DIR,path), "wb") as f:
|
| 49 |
+
for chunk in image_data.chunks():
|
| 50 |
+
f.write(chunk)
|
| 51 |
+
f.close()
|
| 52 |
+
return path
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
def cleanup():
|
| 57 |
+
if (os.path.exists(os.path.join(DIR, "input.jpg"))):
|
| 58 |
+
os.remove(os.path.join(DIR, "input.jpg"))
|
| 59 |
+
if (os.path.exists(os.path.join(DIR, "colorized.jpg"))):
|
| 60 |
+
os.remove(os.path.join(DIR, "colorized.jpg"))
|
imageModel/utils/models/colorization_deploy_v2.prototxt
ADDED
|
@@ -0,0 +1,589 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
name: "LtoAB"
|
| 2 |
+
|
| 3 |
+
layer {
|
| 4 |
+
name: "data_l"
|
| 5 |
+
type: "Input"
|
| 6 |
+
top: "data_l"
|
| 7 |
+
input_param {
|
| 8 |
+
shape { dim: 1 dim: 1 dim: 224 dim: 224 }
|
| 9 |
+
}
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
# *****************
|
| 13 |
+
# ***** conv1 *****
|
| 14 |
+
# *****************
|
| 15 |
+
layer {
|
| 16 |
+
name: "bw_conv1_1"
|
| 17 |
+
type: "Convolution"
|
| 18 |
+
bottom: "data_l"
|
| 19 |
+
top: "conv1_1"
|
| 20 |
+
# param {lr_mult: 0 decay_mult: 0}
|
| 21 |
+
# param {lr_mult: 0 decay_mult: 0}
|
| 22 |
+
convolution_param {
|
| 23 |
+
num_output: 64
|
| 24 |
+
pad: 1
|
| 25 |
+
kernel_size: 3
|
| 26 |
+
}
|
| 27 |
+
}
|
| 28 |
+
layer {
|
| 29 |
+
name: "relu1_1"
|
| 30 |
+
type: "ReLU"
|
| 31 |
+
bottom: "conv1_1"
|
| 32 |
+
top: "conv1_1"
|
| 33 |
+
}
|
| 34 |
+
layer {
|
| 35 |
+
name: "conv1_2"
|
| 36 |
+
type: "Convolution"
|
| 37 |
+
bottom: "conv1_1"
|
| 38 |
+
top: "conv1_2"
|
| 39 |
+
# param {lr_mult: 0 decay_mult: 0}
|
| 40 |
+
# param {lr_mult: 0 decay_mult: 0}
|
| 41 |
+
convolution_param {
|
| 42 |
+
num_output: 64
|
| 43 |
+
pad: 1
|
| 44 |
+
kernel_size: 3
|
| 45 |
+
stride: 2
|
| 46 |
+
}
|
| 47 |
+
}
|
| 48 |
+
layer {
|
| 49 |
+
name: "relu1_2"
|
| 50 |
+
type: "ReLU"
|
| 51 |
+
bottom: "conv1_2"
|
| 52 |
+
top: "conv1_2"
|
| 53 |
+
}
|
| 54 |
+
layer {
|
| 55 |
+
name: "conv1_2norm"
|
| 56 |
+
type: "BatchNorm"
|
| 57 |
+
bottom: "conv1_2"
|
| 58 |
+
top: "conv1_2norm"
|
| 59 |
+
batch_norm_param{ }
|
| 60 |
+
param {lr_mult: 0 decay_mult: 0}
|
| 61 |
+
param {lr_mult: 0 decay_mult: 0}
|
| 62 |
+
param {lr_mult: 0 decay_mult: 0}
|
| 63 |
+
}
|
| 64 |
+
# *****************
|
| 65 |
+
# ***** conv2 *****
|
| 66 |
+
# *****************
|
| 67 |
+
layer {
|
| 68 |
+
name: "conv2_1"
|
| 69 |
+
type: "Convolution"
|
| 70 |
+
# bottom: "conv1_2"
|
| 71 |
+
bottom: "conv1_2norm"
|
| 72 |
+
# bottom: "pool1"
|
| 73 |
+
top: "conv2_1"
|
| 74 |
+
# param {lr_mult: 0 decay_mult: 0}
|
| 75 |
+
# param {lr_mult: 0 decay_mult: 0}
|
| 76 |
+
convolution_param {
|
| 77 |
+
num_output: 128
|
| 78 |
+
pad: 1
|
| 79 |
+
kernel_size: 3
|
| 80 |
+
}
|
| 81 |
+
}
|
| 82 |
+
layer {
|
| 83 |
+
name: "relu2_1"
|
| 84 |
+
type: "ReLU"
|
| 85 |
+
bottom: "conv2_1"
|
| 86 |
+
top: "conv2_1"
|
| 87 |
+
}
|
| 88 |
+
layer {
|
| 89 |
+
name: "conv2_2"
|
| 90 |
+
type: "Convolution"
|
| 91 |
+
bottom: "conv2_1"
|
| 92 |
+
top: "conv2_2"
|
| 93 |
+
# param {lr_mult: 0 decay_mult: 0}
|
| 94 |
+
# param {lr_mult: 0 decay_mult: 0}
|
| 95 |
+
convolution_param {
|
| 96 |
+
num_output: 128
|
| 97 |
+
pad: 1
|
| 98 |
+
kernel_size: 3
|
| 99 |
+
stride: 2
|
| 100 |
+
}
|
| 101 |
+
}
|
| 102 |
+
layer {
|
| 103 |
+
name: "relu2_2"
|
| 104 |
+
type: "ReLU"
|
| 105 |
+
bottom: "conv2_2"
|
| 106 |
+
top: "conv2_2"
|
| 107 |
+
}
|
| 108 |
+
layer {
|
| 109 |
+
name: "conv2_2norm"
|
| 110 |
+
type: "BatchNorm"
|
| 111 |
+
bottom: "conv2_2"
|
| 112 |
+
top: "conv2_2norm"
|
| 113 |
+
batch_norm_param{ }
|
| 114 |
+
param {lr_mult: 0 decay_mult: 0}
|
| 115 |
+
param {lr_mult: 0 decay_mult: 0}
|
| 116 |
+
param {lr_mult: 0 decay_mult: 0}
|
| 117 |
+
}
|
| 118 |
+
# *****************
|
| 119 |
+
# ***** conv3 *****
|
| 120 |
+
# *****************
|
| 121 |
+
layer {
|
| 122 |
+
name: "conv3_1"
|
| 123 |
+
type: "Convolution"
|
| 124 |
+
# bottom: "conv2_2"
|
| 125 |
+
bottom: "conv2_2norm"
|
| 126 |
+
# bottom: "pool2"
|
| 127 |
+
top: "conv3_1"
|
| 128 |
+
# param {lr_mult: 0 decay_mult: 0}
|
| 129 |
+
# param {lr_mult: 0 decay_mult: 0}
|
| 130 |
+
convolution_param {
|
| 131 |
+
num_output: 256
|
| 132 |
+
pad: 1
|
| 133 |
+
kernel_size: 3
|
| 134 |
+
}
|
| 135 |
+
}
|
| 136 |
+
layer {
|
| 137 |
+
name: "relu3_1"
|
| 138 |
+
type: "ReLU"
|
| 139 |
+
bottom: "conv3_1"
|
| 140 |
+
top: "conv3_1"
|
| 141 |
+
}
|
| 142 |
+
layer {
|
| 143 |
+
name: "conv3_2"
|
| 144 |
+
type: "Convolution"
|
| 145 |
+
bottom: "conv3_1"
|
| 146 |
+
top: "conv3_2"
|
| 147 |
+
# param {lr_mult: 0 decay_mult: 0}
|
| 148 |
+
# param {lr_mult: 0 decay_mult: 0}
|
| 149 |
+
convolution_param {
|
| 150 |
+
num_output: 256
|
| 151 |
+
pad: 1
|
| 152 |
+
kernel_size: 3
|
| 153 |
+
}
|
| 154 |
+
}
|
| 155 |
+
layer {
|
| 156 |
+
name: "relu3_2"
|
| 157 |
+
type: "ReLU"
|
| 158 |
+
bottom: "conv3_2"
|
| 159 |
+
top: "conv3_2"
|
| 160 |
+
}
|
| 161 |
+
layer {
|
| 162 |
+
name: "conv3_3"
|
| 163 |
+
type: "Convolution"
|
| 164 |
+
bottom: "conv3_2"
|
| 165 |
+
top: "conv3_3"
|
| 166 |
+
# param {lr_mult: 0 decay_mult: 0}
|
| 167 |
+
# param {lr_mult: 0 decay_mult: 0}
|
| 168 |
+
convolution_param {
|
| 169 |
+
num_output: 256
|
| 170 |
+
pad: 1
|
| 171 |
+
kernel_size: 3
|
| 172 |
+
stride: 2
|
| 173 |
+
}
|
| 174 |
+
}
|
| 175 |
+
layer {
|
| 176 |
+
name: "relu3_3"
|
| 177 |
+
type: "ReLU"
|
| 178 |
+
bottom: "conv3_3"
|
| 179 |
+
top: "conv3_3"
|
| 180 |
+
}
|
| 181 |
+
layer {
|
| 182 |
+
name: "conv3_3norm"
|
| 183 |
+
type: "BatchNorm"
|
| 184 |
+
bottom: "conv3_3"
|
| 185 |
+
top: "conv3_3norm"
|
| 186 |
+
batch_norm_param{ }
|
| 187 |
+
param {lr_mult: 0 decay_mult: 0}
|
| 188 |
+
param {lr_mult: 0 decay_mult: 0}
|
| 189 |
+
param {lr_mult: 0 decay_mult: 0}
|
| 190 |
+
}
|
| 191 |
+
# *****************
|
| 192 |
+
# ***** conv4 *****
|
| 193 |
+
# *****************
|
| 194 |
+
layer {
|
| 195 |
+
name: "conv4_1"
|
| 196 |
+
type: "Convolution"
|
| 197 |
+
# bottom: "conv3_3"
|
| 198 |
+
bottom: "conv3_3norm"
|
| 199 |
+
# bottom: "pool3"
|
| 200 |
+
top: "conv4_1"
|
| 201 |
+
# param {lr_mult: 0 decay_mult: 0}
|
| 202 |
+
# param {lr_mult: 0 decay_mult: 0}
|
| 203 |
+
convolution_param {
|
| 204 |
+
num_output: 512
|
| 205 |
+
kernel_size: 3
|
| 206 |
+
stride: 1
|
| 207 |
+
pad: 1
|
| 208 |
+
dilation: 1
|
| 209 |
+
}
|
| 210 |
+
}
|
| 211 |
+
layer {
|
| 212 |
+
name: "relu4_1"
|
| 213 |
+
type: "ReLU"
|
| 214 |
+
bottom: "conv4_1"
|
| 215 |
+
top: "conv4_1"
|
| 216 |
+
}
|
| 217 |
+
layer {
|
| 218 |
+
name: "conv4_2"
|
| 219 |
+
type: "Convolution"
|
| 220 |
+
bottom: "conv4_1"
|
| 221 |
+
top: "conv4_2"
|
| 222 |
+
# param {lr_mult: 0 decay_mult: 0}
|
| 223 |
+
# param {lr_mult: 0 decay_mult: 0}
|
| 224 |
+
convolution_param {
|
| 225 |
+
num_output: 512
|
| 226 |
+
kernel_size: 3
|
| 227 |
+
stride: 1
|
| 228 |
+
pad: 1
|
| 229 |
+
dilation: 1
|
| 230 |
+
}
|
| 231 |
+
}
|
| 232 |
+
layer {
|
| 233 |
+
name: "relu4_2"
|
| 234 |
+
type: "ReLU"
|
| 235 |
+
bottom: "conv4_2"
|
| 236 |
+
top: "conv4_2"
|
| 237 |
+
}
|
| 238 |
+
layer {
|
| 239 |
+
name: "conv4_3"
|
| 240 |
+
type: "Convolution"
|
| 241 |
+
bottom: "conv4_2"
|
| 242 |
+
top: "conv4_3"
|
| 243 |
+
# param {lr_mult: 0 decay_mult: 0}
|
| 244 |
+
# param {lr_mult: 0 decay_mult: 0}
|
| 245 |
+
convolution_param {
|
| 246 |
+
num_output: 512
|
| 247 |
+
kernel_size: 3
|
| 248 |
+
stride: 1
|
| 249 |
+
pad: 1
|
| 250 |
+
dilation: 1
|
| 251 |
+
}
|
| 252 |
+
}
|
| 253 |
+
layer {
|
| 254 |
+
name: "relu4_3"
|
| 255 |
+
type: "ReLU"
|
| 256 |
+
bottom: "conv4_3"
|
| 257 |
+
top: "conv4_3"
|
| 258 |
+
}
|
| 259 |
+
layer {
|
| 260 |
+
name: "conv4_3norm"
|
| 261 |
+
type: "BatchNorm"
|
| 262 |
+
bottom: "conv4_3"
|
| 263 |
+
top: "conv4_3norm"
|
| 264 |
+
batch_norm_param{ }
|
| 265 |
+
param {lr_mult: 0 decay_mult: 0}
|
| 266 |
+
param {lr_mult: 0 decay_mult: 0}
|
| 267 |
+
param {lr_mult: 0 decay_mult: 0}
|
| 268 |
+
}
|
| 269 |
+
# *****************
|
| 270 |
+
# ***** conv5 *****
|
| 271 |
+
# *****************
|
| 272 |
+
layer {
|
| 273 |
+
name: "conv5_1"
|
| 274 |
+
type: "Convolution"
|
| 275 |
+
# bottom: "conv4_3"
|
| 276 |
+
bottom: "conv4_3norm"
|
| 277 |
+
# bottom: "pool4"
|
| 278 |
+
top: "conv5_1"
|
| 279 |
+
# param {lr_mult: 0 decay_mult: 0}
|
| 280 |
+
# param {lr_mult: 0 decay_mult: 0}
|
| 281 |
+
convolution_param {
|
| 282 |
+
num_output: 512
|
| 283 |
+
kernel_size: 3
|
| 284 |
+
stride: 1
|
| 285 |
+
pad: 2
|
| 286 |
+
dilation: 2
|
| 287 |
+
}
|
| 288 |
+
}
|
| 289 |
+
layer {
|
| 290 |
+
name: "relu5_1"
|
| 291 |
+
type: "ReLU"
|
| 292 |
+
bottom: "conv5_1"
|
| 293 |
+
top: "conv5_1"
|
| 294 |
+
}
|
| 295 |
+
layer {
|
| 296 |
+
name: "conv5_2"
|
| 297 |
+
type: "Convolution"
|
| 298 |
+
bottom: "conv5_1"
|
| 299 |
+
top: "conv5_2"
|
| 300 |
+
# param {lr_mult: 0 decay_mult: 0}
|
| 301 |
+
# param {lr_mult: 0 decay_mult: 0}
|
| 302 |
+
convolution_param {
|
| 303 |
+
num_output: 512
|
| 304 |
+
kernel_size: 3
|
| 305 |
+
stride: 1
|
| 306 |
+
pad: 2
|
| 307 |
+
dilation: 2
|
| 308 |
+
}
|
| 309 |
+
}
|
| 310 |
+
layer {
|
| 311 |
+
name: "relu5_2"
|
| 312 |
+
type: "ReLU"
|
| 313 |
+
bottom: "conv5_2"
|
| 314 |
+
top: "conv5_2"
|
| 315 |
+
}
|
| 316 |
+
layer {
|
| 317 |
+
name: "conv5_3"
|
| 318 |
+
type: "Convolution"
|
| 319 |
+
bottom: "conv5_2"
|
| 320 |
+
top: "conv5_3"
|
| 321 |
+
# param {lr_mult: 0 decay_mult: 0}
|
| 322 |
+
# param {lr_mult: 0 decay_mult: 0}
|
| 323 |
+
convolution_param {
|
| 324 |
+
num_output: 512
|
| 325 |
+
kernel_size: 3
|
| 326 |
+
stride: 1
|
| 327 |
+
pad: 2
|
| 328 |
+
dilation: 2
|
| 329 |
+
}
|
| 330 |
+
}
|
| 331 |
+
layer {
|
| 332 |
+
name: "relu5_3"
|
| 333 |
+
type: "ReLU"
|
| 334 |
+
bottom: "conv5_3"
|
| 335 |
+
top: "conv5_3"
|
| 336 |
+
}
|
| 337 |
+
layer {
|
| 338 |
+
name: "conv5_3norm"
|
| 339 |
+
type: "BatchNorm"
|
| 340 |
+
bottom: "conv5_3"
|
| 341 |
+
top: "conv5_3norm"
|
| 342 |
+
batch_norm_param{ }
|
| 343 |
+
param {lr_mult: 0 decay_mult: 0}
|
| 344 |
+
param {lr_mult: 0 decay_mult: 0}
|
| 345 |
+
param {lr_mult: 0 decay_mult: 0}
|
| 346 |
+
}
|
| 347 |
+
# *****************
|
| 348 |
+
# ***** conv6 *****
|
| 349 |
+
# *****************
|
| 350 |
+
layer {
|
| 351 |
+
name: "conv6_1"
|
| 352 |
+
type: "Convolution"
|
| 353 |
+
bottom: "conv5_3norm"
|
| 354 |
+
top: "conv6_1"
|
| 355 |
+
convolution_param {
|
| 356 |
+
num_output: 512
|
| 357 |
+
kernel_size: 3
|
| 358 |
+
pad: 2
|
| 359 |
+
dilation: 2
|
| 360 |
+
}
|
| 361 |
+
}
|
| 362 |
+
layer {
|
| 363 |
+
name: "relu6_1"
|
| 364 |
+
type: "ReLU"
|
| 365 |
+
bottom: "conv6_1"
|
| 366 |
+
top: "conv6_1"
|
| 367 |
+
}
|
| 368 |
+
layer {
|
| 369 |
+
name: "conv6_2"
|
| 370 |
+
type: "Convolution"
|
| 371 |
+
bottom: "conv6_1"
|
| 372 |
+
top: "conv6_2"
|
| 373 |
+
convolution_param {
|
| 374 |
+
num_output: 512
|
| 375 |
+
kernel_size: 3
|
| 376 |
+
pad: 2
|
| 377 |
+
dilation: 2
|
| 378 |
+
}
|
| 379 |
+
}
|
| 380 |
+
layer {
|
| 381 |
+
name: "relu6_2"
|
| 382 |
+
type: "ReLU"
|
| 383 |
+
bottom: "conv6_2"
|
| 384 |
+
top: "conv6_2"
|
| 385 |
+
}
|
| 386 |
+
layer {
|
| 387 |
+
name: "conv6_3"
|
| 388 |
+
type: "Convolution"
|
| 389 |
+
bottom: "conv6_2"
|
| 390 |
+
top: "conv6_3"
|
| 391 |
+
convolution_param {
|
| 392 |
+
num_output: 512
|
| 393 |
+
kernel_size: 3
|
| 394 |
+
pad: 2
|
| 395 |
+
dilation: 2
|
| 396 |
+
}
|
| 397 |
+
}
|
| 398 |
+
layer {
|
| 399 |
+
name: "relu6_3"
|
| 400 |
+
type: "ReLU"
|
| 401 |
+
bottom: "conv6_3"
|
| 402 |
+
top: "conv6_3"
|
| 403 |
+
}
|
| 404 |
+
layer {
|
| 405 |
+
name: "conv6_3norm"
|
| 406 |
+
type: "BatchNorm"
|
| 407 |
+
bottom: "conv6_3"
|
| 408 |
+
top: "conv6_3norm"
|
| 409 |
+
batch_norm_param{ }
|
| 410 |
+
param {lr_mult: 0 decay_mult: 0}
|
| 411 |
+
param {lr_mult: 0 decay_mult: 0}
|
| 412 |
+
param {lr_mult: 0 decay_mult: 0}
|
| 413 |
+
}
|
| 414 |
+
# *****************
|
| 415 |
+
# ***** conv7 *****
|
| 416 |
+
# *****************
|
| 417 |
+
layer {
|
| 418 |
+
name: "conv7_1"
|
| 419 |
+
type: "Convolution"
|
| 420 |
+
bottom: "conv6_3norm"
|
| 421 |
+
top: "conv7_1"
|
| 422 |
+
convolution_param {
|
| 423 |
+
num_output: 512
|
| 424 |
+
kernel_size: 3
|
| 425 |
+
pad: 1
|
| 426 |
+
dilation: 1
|
| 427 |
+
}
|
| 428 |
+
}
|
| 429 |
+
layer {
|
| 430 |
+
name: "relu7_1"
|
| 431 |
+
type: "ReLU"
|
| 432 |
+
bottom: "conv7_1"
|
| 433 |
+
top: "conv7_1"
|
| 434 |
+
}
|
| 435 |
+
layer {
|
| 436 |
+
name: "conv7_2"
|
| 437 |
+
type: "Convolution"
|
| 438 |
+
bottom: "conv7_1"
|
| 439 |
+
top: "conv7_2"
|
| 440 |
+
convolution_param {
|
| 441 |
+
num_output: 512
|
| 442 |
+
kernel_size: 3
|
| 443 |
+
pad: 1
|
| 444 |
+
dilation: 1
|
| 445 |
+
}
|
| 446 |
+
}
|
| 447 |
+
layer {
|
| 448 |
+
name: "relu7_2"
|
| 449 |
+
type: "ReLU"
|
| 450 |
+
bottom: "conv7_2"
|
| 451 |
+
top: "conv7_2"
|
| 452 |
+
}
|
| 453 |
+
layer {
|
| 454 |
+
name: "conv7_3"
|
| 455 |
+
type: "Convolution"
|
| 456 |
+
bottom: "conv7_2"
|
| 457 |
+
top: "conv7_3"
|
| 458 |
+
convolution_param {
|
| 459 |
+
num_output: 512
|
| 460 |
+
kernel_size: 3
|
| 461 |
+
pad: 1
|
| 462 |
+
dilation: 1
|
| 463 |
+
}
|
| 464 |
+
}
|
| 465 |
+
layer {
|
| 466 |
+
name: "relu7_3"
|
| 467 |
+
type: "ReLU"
|
| 468 |
+
bottom: "conv7_3"
|
| 469 |
+
top: "conv7_3"
|
| 470 |
+
}
|
| 471 |
+
layer {
|
| 472 |
+
name: "conv7_3norm"
|
| 473 |
+
type: "BatchNorm"
|
| 474 |
+
bottom: "conv7_3"
|
| 475 |
+
top: "conv7_3norm"
|
| 476 |
+
batch_norm_param{ }
|
| 477 |
+
param {lr_mult: 0 decay_mult: 0}
|
| 478 |
+
param {lr_mult: 0 decay_mult: 0}
|
| 479 |
+
param {lr_mult: 0 decay_mult: 0}
|
| 480 |
+
}
|
| 481 |
+
# *****************
|
| 482 |
+
# ***** conv8 *****
|
| 483 |
+
# *****************
|
| 484 |
+
layer {
|
| 485 |
+
name: "conv8_1"
|
| 486 |
+
type: "Deconvolution"
|
| 487 |
+
bottom: "conv7_3norm"
|
| 488 |
+
top: "conv8_1"
|
| 489 |
+
convolution_param {
|
| 490 |
+
num_output: 256
|
| 491 |
+
kernel_size: 4
|
| 492 |
+
pad: 1
|
| 493 |
+
dilation: 1
|
| 494 |
+
stride: 2
|
| 495 |
+
}
|
| 496 |
+
}
|
| 497 |
+
layer {
|
| 498 |
+
name: "relu8_1"
|
| 499 |
+
type: "ReLU"
|
| 500 |
+
bottom: "conv8_1"
|
| 501 |
+
top: "conv8_1"
|
| 502 |
+
}
|
| 503 |
+
layer {
|
| 504 |
+
name: "conv8_2"
|
| 505 |
+
type: "Convolution"
|
| 506 |
+
bottom: "conv8_1"
|
| 507 |
+
top: "conv8_2"
|
| 508 |
+
convolution_param {
|
| 509 |
+
num_output: 256
|
| 510 |
+
kernel_size: 3
|
| 511 |
+
pad: 1
|
| 512 |
+
dilation: 1
|
| 513 |
+
}
|
| 514 |
+
}
|
| 515 |
+
layer {
|
| 516 |
+
name: "relu8_2"
|
| 517 |
+
type: "ReLU"
|
| 518 |
+
bottom: "conv8_2"
|
| 519 |
+
top: "conv8_2"
|
| 520 |
+
}
|
| 521 |
+
layer {
|
| 522 |
+
name: "conv8_3"
|
| 523 |
+
type: "Convolution"
|
| 524 |
+
bottom: "conv8_2"
|
| 525 |
+
top: "conv8_3"
|
| 526 |
+
convolution_param {
|
| 527 |
+
num_output: 256
|
| 528 |
+
kernel_size: 3
|
| 529 |
+
pad: 1
|
| 530 |
+
dilation: 1
|
| 531 |
+
}
|
| 532 |
+
}
|
| 533 |
+
layer {
|
| 534 |
+
name: "relu8_3"
|
| 535 |
+
type: "ReLU"
|
| 536 |
+
bottom: "conv8_3"
|
| 537 |
+
top: "conv8_3"
|
| 538 |
+
}
|
| 539 |
+
# *******************
|
| 540 |
+
# ***** Softmax *****
|
| 541 |
+
# *******************
|
| 542 |
+
layer {
|
| 543 |
+
name: "conv8_313"
|
| 544 |
+
type: "Convolution"
|
| 545 |
+
bottom: "conv8_3"
|
| 546 |
+
top: "conv8_313"
|
| 547 |
+
convolution_param {
|
| 548 |
+
num_output: 313
|
| 549 |
+
kernel_size: 1
|
| 550 |
+
stride: 1
|
| 551 |
+
dilation: 1
|
| 552 |
+
}
|
| 553 |
+
}
|
| 554 |
+
layer {
|
| 555 |
+
name: "conv8_313_rh"
|
| 556 |
+
type: "Scale"
|
| 557 |
+
bottom: "conv8_313"
|
| 558 |
+
top: "conv8_313_rh"
|
| 559 |
+
scale_param {
|
| 560 |
+
bias_term: false
|
| 561 |
+
filler { type: 'constant' value: 2.606 }
|
| 562 |
+
}
|
| 563 |
+
}
|
| 564 |
+
layer {
|
| 565 |
+
name: "class8_313_rh"
|
| 566 |
+
type: "Softmax"
|
| 567 |
+
bottom: "conv8_313_rh"
|
| 568 |
+
top: "class8_313_rh"
|
| 569 |
+
}
|
| 570 |
+
# ********************
|
| 571 |
+
# ***** Decoding *****
|
| 572 |
+
# ********************
|
| 573 |
+
layer {
|
| 574 |
+
name: "class8_ab"
|
| 575 |
+
type: "Convolution"
|
| 576 |
+
bottom: "class8_313_rh"
|
| 577 |
+
top: "class8_ab"
|
| 578 |
+
convolution_param {
|
| 579 |
+
num_output: 2
|
| 580 |
+
kernel_size: 1
|
| 581 |
+
stride: 1
|
| 582 |
+
dilation: 1
|
| 583 |
+
}
|
| 584 |
+
}
|
| 585 |
+
layer {
|
| 586 |
+
name: "Silence"
|
| 587 |
+
type: "Silence"
|
| 588 |
+
bottom: "class8_ab"
|
| 589 |
+
}
|
imageModel/utils/models/colorization_release_v2.caffemodel
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:f5af1e602646328c792e1094f9876fe9cd4c09ac46fa886e5708a1abc89137b1
|
| 3 |
+
size 128946764
|
imageModel/utils/models/pts_in_hull.npy
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b5dec01315c34f43f1c8c089e84c45ae35d1838d8e77ed0e7ca930f79ffa450e
|
| 3 |
+
size 5088
|
imageModel/views.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from rest_framework.views import APIView
|
| 2 |
+
from .utils.main import colorize, save_image, cleanup
|
| 3 |
+
from django.http import FileResponse, JsonResponse
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
# [GET/POST] /api/colourize/
|
| 8 |
+
class ImageModelView(APIView):
|
| 9 |
+
def get(self):
|
| 10 |
+
cleanup()
|
| 11 |
+
output = colorize("sample.jpg")
|
| 12 |
+
return FileResponse(open(output, "rb"), content_type="image/jpeg")
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def post(self, request):
|
| 16 |
+
cleanup()
|
| 17 |
+
image_data = request.FILES.get('image')
|
| 18 |
+
image_path = save_image(image_data, "input.jpg")
|
| 19 |
+
|
| 20 |
+
output_path = colorize(image_path)
|
| 21 |
+
|
| 22 |
+
# return FileResponse(open(output_path, "rb"), content_type="image/jpeg")
|
| 23 |
+
|
| 24 |
+
with open(output_path, 'rb') as f:
|
| 25 |
+
image_data = f.read()
|
| 26 |
+
|
| 27 |
+
response = JsonResponse({'image': image_data.decode('latin1')})
|
| 28 |
+
response['Content-Disposition'] = 'attachment; filename="output.jpg"'
|
| 29 |
+
return response
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
# try out image captioning
|
manage.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python
|
| 2 |
+
"""Django's command-line utility for administrative tasks."""
|
| 3 |
+
import os
|
| 4 |
+
import sys
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
def main():
|
| 8 |
+
"""Run administrative tasks."""
|
| 9 |
+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'colourize.settings')
|
| 10 |
+
try:
|
| 11 |
+
from django.core.management import execute_from_command_line
|
| 12 |
+
except ImportError as exc:
|
| 13 |
+
raise ImportError(
|
| 14 |
+
"Couldn't import Django. Are you sure it's installed and "
|
| 15 |
+
"available on your PYTHONPATH environment variable? Did you "
|
| 16 |
+
"forget to activate a virtual environment?"
|
| 17 |
+
) from exc
|
| 18 |
+
execute_from_command_line(sys.argv)
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
if __name__ == '__main__':
|
| 22 |
+
main()
|
requirements.txt
ADDED
|
Binary file (1.35 kB). View file
|
|
|