Geotensor
Geometric low-rank tensor completion for color image inpainting.
Install / Use
/learn @xinychen/GeotensorREADME
geotensor
Motivation
- Color image inpainting: Various missing patterns.
- Low-rank tensor completion: Characterizing images with graph (e.g., adjacent smoothness matrix based graph regularizer).
Implementation
One notable thing is that unlike the complex equations in our models, our Python implementation (relies on numpy) is extremely easy to work with. Take GLTC-Geman as an example, its kernel only has few lines:
def supergradient(s_hat, lambda0, theta):
"""Supergradient of the Geman function."""
return (lambda0 * theta / (s_hat + theta) ** 2)
def GLTC_Geman(dense_tensor, sparse_tensor, alpha, beta, rho, theta, maxiter):
"""Main function of the GLTC-Geman."""
dim0 = sparse_tensor.ndim
dim1, dim2, dim3 = sparse_tensor.shape
dim = np.array([dim1, dim2, dim3])
binary_tensor = np.zeros((dim1, dim2, dim3))
binary_tensor[np.where(sparse_tensor != 0)] = 1
tensor_hat = sparse_tensor.copy()
X = np.zeros((dim1, dim2, dim3, dim0)) # \boldsymbol{\mathcal{X}} (n1*n2*3*d)
Z = np.zeros((dim1, dim2, dim3, dim0)) # \boldsymbol{\mathcal{Z}} (n1*n2*3*d)
T = np.zeros((dim1, dim2, dim3, dim0)) # \boldsymbol{\mathcal{T}} (n1*n2*3*d)
for k in range(dim0):
X[:, :, :, k] = tensor_hat
Z[:, :, :, k] = tensor_hat
D1 = np.zeros((dim1 - 1, dim1)) # (n1-1)-by-n1 adjacent smoothness matrix
for i in range(dim1 - 1):
D1[i, i] = -1
D1[i, i + 1] = 1
D2 = np.zeros((dim2 - 1, dim2)) # (n2-1)-by-n2 adjacent smoothness matrix
for i in range(dim2 - 1):
D2[i, i] = -1
D2[i, i + 1] = 1
w = []
for k in range(dim0):
u, s, v = np.linalg.svd(ten2mat(Z[:, :, :, k], k), full_matrices = 0)
w.append(np.zeros(len(s)))
for i in range(len(np.where(s > 0)[0])):
w[k][i] = supergradient(s[i], alpha, theta)
for iters in range(maxiter):
for k in range(dim0):
u, s, v = np.linalg.svd(ten2mat(X[:, :, :, k] + T[:, :, :, k] / rho, k), full_matrices = 0)
for i in range(len(np.where(w[k] > 0)[0])):
s[i] = max(s[i] - w[k][i] / rho, 0)
Z[:, :, :, k] = mat2ten(np.matmul(np.matmul(u, np.diag(s)), v), dim, k)
var = ten2mat(rho * Z[:, :, :, k] - T[:, :, :, k], k)
if k == 0:
var0 = mat2ten(np.matmul(inv(beta * np.matmul(D1.T, D1) + rho * np.eye(dim1)), var), dim, k)
elif k == 1:
var0 = mat2ten(np.matmul(inv(beta * np.matmul(D2.T, D2) + rho * np.eye(dim2)), var), dim, k)
else:
var0 = Z[:, :, :, k] - T[:, :, :, k] / rho
X[:, :, :, k] = np.multiply(1 - binary_tensor, var0) + sparse_tensor
uz, sz, vz = np.linalg.svd(ten2mat(Z[:, :, :, k], k), full_matrices = 0)
for i in range(len(np.where(sz > 0)[0])):
w[k][i] = supergradient(sz[i], alpha, theta)
tensor_hat = np.mean(X, axis = 3)
for k in range(dim0):
T[:, :, :, k] = T[:, :, :, k] + rho * (X[:, :, :, k] - Z[:, :, :, k])
X[:, :, :, k] = tensor_hat.copy()
return tensor_hat
Have fun if you work with our code!
-
Competing Models
-
Inpainting Examples (by
GLTC-Geman)
Reference
- General Matrix/Tensor Completion
| No | Title | Year | PDF | Code | |:---|:------|:----:|:---:|-----:| | 1 | Tensor Completion for Estimating Missing Values in Visual Data | 2013 | TPAMI | - | | 2 | Efficient tensor completion for color image and video recovery: Low-rank tensor train | 2016 | arxiv | - | | 3 | Tensor Robust Principal Component Analysis: Exact Recovery of Corrupted Low-Rank Tensors via Convex Optimization | 2016 | CVPR | Matlab | | 4 | Geometric Matrix Completion with Recurrent Multi-Graph Neural Networks | 2017 | NeurIPS| Python | | 5 | Efficient Low Rank Tensor Ring Completion | 2017 | ICCV | Matlab | | 6 | Spatio-Temporal Signal Recovery Based on Low Rank and Differential Smoothness | 2018 | IEEE | - | | 7 | Exact Low Tubal Rank Tensor Recovery from Gaussian Measurements | 2018 | IJCAI | Matlab | | 8 | Tensor Robust Principal Component Analysis with A New Tensor Nuclear Norm | 2018 | TPAMI | Matlab |
- Singular Value Thresholding (SVT)
| No | Title | Year | PDF | Code | |:---|:------|:----:|:---:|-----:| | 1 | A General Iterative Shrinkage and Thresholding Algorithm for Non-convex Regularized Optim
Related Skills
node-connect
340.5kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
84.2kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
340.5kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
commit-push-pr
84.2kCommit, push, and open a PR
