This repository contains code from our article High-Intensified Resemblance and Statistic-Restructured Alignment in Few-Shot Domain Adaptation for Industrial-Specialized Employment
[article]
This work was supported in part by the “Center for Cyber-Physical System Innovation” from the Featured Areas Research Center Program within the framework of the Higher Education Sprout Project by the Ministry of Education in Taiwan.
Note all of this material is for educational purposes only. In the case of actual production, The authors cannot affirm or verify the outcomes based on data obtained outside of this demonstration. Furthermore, it is necessary to verify with the contributor in each proposed technique (e.g., SoftTriplet module and so on) for commercial use rights.
If you find this method helpful, please cite us.
@article{petchhan2023high,
title={High-Intensified Resemblance and Statistic-Restructured Alignment in Few-Shot Domain Adaptation for Industrial-Specialized Employment},
author={Petchhan, Jirayu and Su, Shun-Feng},
journal={IEEE Transactions on Consumer Electronics},
year={2023},
publisher={IEEE}
}
-
Dataset can be downloaded here Office-31 then create a new "data" folder in the project directory and put into its.
-
requirements python==3.8, torch==1.9.0, torchvision==0.10.0, numpy==1.18.1
Note the considered environment runs on GPU with CUDA 11.1 and cuDNN 8.1 package versions. We can not affirm how this would affect working this env. with other package versions.
- Reproducible is by using the given function and any information in this repo (please read the license and policy, open and/or discuss the issues with us, and cite our paper).
- Once, the below algorithm is using inferred outputs as inputs from both source and target domains calculated in our proposed function to obtain re-patterned covariance matrices for aligning.
Note the testing was conducted with 3x3, 4x4, and 5x5 artificial covariance matrices running on the CPU implementation for demonstration. The available results showed only the 1st iteration for Covsqrt and Spectralcov in Colab.
def simplestrucCORAL(source, target):
d = source.data.shape[1]
# Standardization
s_ = source - torch.mean(source, 0, keepdim=True)
t_ = target - torch.mean(target, 0, keepdim=True)
# Initial covariance matrices
simple_cov_s = s_ @ s_.t()
simple_cov_t = t_ @ t_.t()
# Re-structuring (b=1 only)
I = torch.eye(int(simple_cov_s.shape[0]))
D_s = torch.diag(torch.sub(I, torch.mm(s_, s_.t())))
D_t = torch.diag(torch.sub(I, torch.mm(t_, t_.t())))
# Covariance matrices with b=1 factor structure
cov_s = simple_cov_s + D_s
cov_t = simple_cov_t + D_t
# Addressing nearness distances in Frobenius-norm space
L2 = torch.mul((cov_s - cov_t), (cov_s - cov_t))
mean = torch.mean(L2)
loss = mean/(4*d*d)
return loss
To re-structure statistical representations (With the number of b factors) for re-structural correlation alignment
def b_structure(Cov, order=1):
# Initial
iter = 1
A0 = Cov
# Identity matrix
I = torch.eye(int(A0.shape[0])).cuda()
# First factor (b=1)
# diag
diag_b1 = torch.diag(I-A0)
#Structural Symmetric Correlation Matrix (A @ b=1)
A = A0 + diag_b1
# b factor>=2
while iter < order:
if order==1: print("break b factor iterative re-patterning corr if b==1"); break # double-check for breaking iterative corr
iter += 1
# b factor iterative structural nearest corr; X(t)
A = A + torch.diag(I-A)
return A
def spectralCORAL(source, target, order=2):
d = source.data.shape[1]
s_ = source - torch.mean(source, 0, keepdim=True)
t_ = target - torch.mean(target, 0, keepdim=True)
cov_s = torch.matmul(s_, s_.t())
cov_t = torch.matmul(t_, t_.t())
b_cov_s = b_structure(cov_s, order)
b_cov_t = b_structure(cov_t, order)
# L2 Frobenius Norm
L2 = torch.mul((b_cov_s - b_cov_t), (b_cov_s - b_cov_t))
mean = torch.mean(L2)
loss = mean/(4*d*d)
return loss
Training Spectral-CORAL adaptation task under vanilla classifier
Remark: The initial state and whole training was set the initial state at varying-way five-shot training all along.
python main.py --model resnet50 --n_epoches 100 --n_target_samples 5 --batch_size 31 --mini_batch_size_g_h 31 --data_type office31 --source amazon --target webcam --dim 31 --C 31 --K 1 --la 1 --att_type n --tf_inv_loss spectralcoral --robust_order 6 --metatest n --mutation r --mutation_style mixup --alpha_mix 0.2 --da_type UDA
Training Spectral-CORAL adaptation task 'n Attention Orchestration with SoftTriplet classifier (as the proposed STOS scheme)
Remark: We set five multiple centers as follows in our hyperparameter setting of our published article for batch training.
python main.py --model resnet50 --n_epoches 100 --n_target_samples 5 --batch_size 31 --mini_batch_size_g_h 31 --data_type office31 --source amazon --target webcam --dim 155 --C 31 --K 5 --la 5 --att_type orcat --tf_inv_loss spectralcoral --robust_order 6 --metatest n --mutation r --mutation_style mixup --alpha_mix 0.2 --da_type UDA
- 2022/07/11 - All related files are under preparation.
- 2022/08/12 - All techniques and networks in this study are available.
- 2022/08/14 - Pre-release of the batch training in adaptation task.
- 2022/08/26 - Apache License 2.0 is included in this resource repository
- 2023/02/16 - Article pre-released (Early access)
- 2023/12/17 - Minor fixes and update information