Git Product home page Git Product logo

mwr's Introduction

[CVPR 2022] Moving Window Regression: A Novel Approach to Ordinal Regression

Official Pytorch Implementation of the CVPR 2022 paper, "Moving Window Regression: A Novel Approach to Ordinal Regression."

Paper

A novel ordinal regression algorithm, called moving window regression (MWR), is proposed in this paper. First, we propose the notion of relative rank (ρ-rank), which is a new order representation scheme for input and reference instances. Second, we develop global and local relative regressors (ρ-regressors) to predict ρ-ranks within entire and specific rank ranges, respectively. Third, we refine an initial rank estimate iteratively by selecting two reference instances to form a search window and then estimating the ρ-rank within the window.

The full paper can be found via the link above.

Datasets

Dependencies

  • Python 3
  • Pytorch

Preprocessing

We use MTCNN for face detection and face alignment code provided from pyimagesearch for face alignment.

Pretrained Models and Reference Lists

You can download models, IMDB-WIKI pretrained model, and reference lists here.

Train

To train MWR, run the script in train_code folder.

python train_code/train.py

Test

Use the following command for evaluation.

python test_code/op.py --dataset Dataset --regression Regression_type --experiment_setting Experimental_setting --im_path Image_path

Cite

@inproceedings{shin2022moving,
  title={Moving window regression: {a} novel approach to ordinal regression},
  author={Shin, Nyeong-Ho and Lee, Seon-Ho and Kim, Chang-Su},
  booktitle={Proceedings of the IEEE/CVF conference on computer vision and pattern recognition},
  year={2022}
}

Other Order Learning Algorithms

License

See MIT License

mwr's People

Contributors

nhshin-mcl avatar

Stargazers

cbsong avatar star avatar  avatar Ozgur Ogul Koca avatar Kimberly avatar chinghsien avatar Veronica Morelli avatar  avatar Sevara Amirullaeva avatar Yiming Lin avatar Yusuke Akamatsu avatar He ShiLong avatar zane.zang avatar phongngrbl avatar  avatar  avatar Ferdinand Könneker avatar Đinh Huy Sáng (Leo) avatar  avatar Zhuo Yang avatar  avatar Ray avatar  avatar Anirudh Som avatar  avatar Peng Liu avatar  avatar Thomas Petit avatar  avatar Zuzanna avatar Zero avatar  avatar 黄文僧 avatar LINGYU ZHOU avatar Johnny Lai avatar Alexey Golunov avatar Pankaj Kumar avatar Chris Kennedy avatar Richard Higgins avatar  avatar Jeff Carpenter avatar  avatar HojunLee avatar Loong avatar Eric O. Korman avatar Hermann Petrov avatar Jaeseung Lee avatar cai avatar Tasks With Code avatar Kyubum Shin  avatar Xin Ding avatar Roald avatar Kucukgz avatar  avatar leo avatar Steven avatar Chenyang Wang avatar Akon Lau  avatar pom_mts avatar  avatar Marius Knorr avatar Inseo Lee avatar biangbiangmian avatar James avatar  avatar tianxing avatar  avatar Tian QIN avatar Dennis Bontempi avatar Jas avatar  avatar Cheng Kang (康成) avatar Dongkwon Jin avatar JunchengWang avatar

Watchers

 avatar

mwr's Issues

Is this a mistake?

MWR/code/Utils.py

Lines 172 to 173 in d070db4

feat_train = torch.as_tensor(features['train'], dtype=torch.float32).to(device).squeeze()
feat_test = torch.as_tensor(features['train'], dtype=torch.float32).to(device).squeeze()

In L173 you have var name "test", but you use features['train'] here. Looks like a mistake. Am I wrong?

Regressor architecture

Dear authors,
in your paper, you describe the regressor $g(\cdot): \mathbb{R}^{N} \rightarrow [-1, 1]$ architecture as composed of three fully connected layers (multi-layer perceptron). See the images below for reference.

image

Screenshot from 2023-01-16 11-27-26

However, in this repository, the regressor is implemented using convolutions with kernel size 1.

MWR/code/Network.py

Lines 18 to 27 in d070db4

class Regressor(nn.Sequential):
def __init__(self, input_channel, output_channel):
super(Regressor, self).__init__()
self.convA = nn.Conv2d(input_channel, output_channel, kernel_size=1, stride=1)
self.leakyreluA = nn.ReLU()
self.convB = nn.Conv2d(output_channel, output_channel, kernel_size=1, stride=1)
self.leakyreluB = nn.ReLU()
self.dropout = nn.Dropout(p=0.5)
self.convC = nn.Conv2d(output_channel, 1, kernel_size=1, stride=1)
self.activation = nn.Tanh()

self.regressor = Regressor(1536, 512)

Fully connected layers are usually implemented using a linear layer. Do you perform some slicing/viewing of the tensors, which makes the implementation equivalent to a linear layer? Or do you use convolutions here by mistake? Can you please elaborate on this?

Jakub

train with pretained gol model

I try to train the regressor only with pretrained gol-weights encoder(freezed) on the same datasets, but it didn't converge to a desirable performance.
To my limited understanding, gol is a way to train the encoder to map the images to a certain feature embedding space where the features extracted from images of people of certain ages would follow those 3 constraints mentioned in gol paper. Therefore, it was supposed to work that use mwr stategy to replace the knn strategy in gol post-process.
Is it because my training procedure went wrong?Or should I try combine these model to train together?

I have a ValueError in code Utils.py

I tried to run op.py with the next command:

python op.py --dataset utk --regression global --experiment_setting coral --im_path UTKFace

But I have a problem with inhomogeneous part of sequence.
The full error text:

  File "/home/vid/hdd/projects/PycharmProjects/MWR2/code/op.py", line 62, in <module>
    global_regression(args, train_data, test_data, sampling=sampling, sample_rate=sample_rate)
  File "/home/vid/hdd/projects/PycharmProjects/MWR2/code/Prediction.py", line 99, in global_regression
    refer_idx, refer_idx_pair = select_reference_global_regression(train_data, pair_idx, np.array(loss_total), limit=1)
  File "/home/vid/hdd/projects/PycharmProjects/MWR2/code/Utils.py", line 98, in select_reference_global_regression
    y_1_idx_tmp, y_2_idx_tmp = idx[row], np.array(pair_idx)[idx[0]][column]
ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (6582,) + inhomogeneous part.

How to fix it?

Screenshot from 2022-12-08 18-15-20

Training process ?

First thanks for your great work. I have a question that how can you evaluate how good your model while training ? I mean that how did you the valid set to evaluate the training model?

Two stages?

Thanks for your excellent work. Is the training two-stage for global regressor and local regressor respectively?

Repeats the code intermediate result

Thank you very much for your code's contribution to the field of ordinal regression. Your code is poetic.Could you please make public the Lower bounds and Upper bounds results you obtained in CLAP2015, and make public the Testing... [1/1436]
Iteration 1:
y1_age, y2_age, pred_mwr
Iteration 2:
y1_age, y2_age, pred_mwr

Because I don't know if the Lower bounds and Upper bounds I get with my own data set are correct, I get the following result:Testing... [1/1436]
Iteration 1:
y1_age: [33.2 31.2 38.2 47.2 44.5]
y2_age: [33.2 31.2 38.2 47.2 44.5]
pred_mwr: 38.85999999999999

Iteration 2:
y1_age: [33.2 31.2 38.2 47.2 44.5]
y2_age: [33.2 31.2 38.2 47.2 44.5]
pred_mwr: 38.85999999999999

T-SNE visualization

Would you please provide pipeline for visualization CLAP2015 dataset (maybe without code, just describing specific steps)? Am I need to use additional 7x7 avg pool after 5'th stage VGG16 for this? Does facial alignment have an impact here?

How to run demos?

Could you please also provide a demo python file? I would like to run the model on my own test images.

Can't use / understand pretrained models to perform inference

Hi, I read your paper and great work!

I have some issues running the models on my images. Given that you provide the model pretrained I expected to use them more or less in this manner

global_model = Network.Global_Regressor()
global_model.load_state_dict(torch.load('global.pth'))
local_models = []
for x in range(num_locals):
    local_m = Network.Local_Regressor()
    local_models.append(local_m.load_state_dict(torch.load(f'local{x}.pth')))

my_image = Image.open(open('face.jpg', 'rb'))
# Preprocess image
my_image = torch.transforms.ToTensor(my_image)

global_output = global_model(my_image)
if global_output == something:
    age = local_models[3][my_image]
elif ....  #other cases 

But your code is super complicated and I don't understand it fully. In particular why the datasets are required if the models are pretrained? And why that's not always the case based on the "sampling" variable (I guess)?

So, basically, I just want to use your approach with the model pretrained on morph (or another dataset) to do inference on my data without ever having to download morph (or any other dataset). Is it possible? If not what do you mean with pretrained models?

Thanks

Question about training model ?

First congratulate for your great work? I have my own dataset and I want to train with your model.
But I have a question about the initial estimation when training. In your paper you wrote that "in the feature space, we find the K NNs to
x among all training instances in terms of the Euclidean distances"

I don't know the feature space your made from the beginning before training model or you got from one batchsize when training ?
Hope you can answer this question for me?

EOFError: Ran out of input

Hi, how to fix this issue, I have train with utk dataset.

(base) test3@ai3:~/Documents/test/ai/ag/ag-v3$ python3.6 code/op.py --dataset utk --regression global --experiment_setting train --im_path /mnt/test3/age
Namespace(backbone='Global_Regressor', ckpt_dir='ckpt', data_path='datalist', dataset='utk', experiment_setting='train', experiment_title='global/utk/train', fold=0, gpu=0, im_path='/mnt/test3/age', regression='global', tau=0.2)
Global Regression
Age range partition:  [[21, 28], [24, 33], [29, 40], [34, 49], [41, 60]]
cuda:0
Get Global_Regressor
ckpt/global/UTK/train/fold0/utk_train.pth
Traceback (most recent call last):
  File "code/op.py", line 62, in <module>
    global_regression(args, train_data, test_data, sampling=sampling, sample_rate=sample_rate)
  File "/home/test3/Documents/test/ai/ag/ag-v3/code/Prediction.py", line 22, in global_regression
    checkpoint = torch.load(initial_model, map_location=device)
  File "/home/test3/.local/lib/python3.6/site-packages/torch/serialization.py", line 593, in load
    return _legacy_load(opened_file, map_location, pickle_module, **pickle_load_args)
  File "/home/test3/.local/lib/python3.6/site-packages/torch/serialization.py", line 763, in _legacy_load
    magic_number = pickle_module.load(f, **pickle_load_args)
EOFError: Ran out of input

preprocessing

would you please share the preprocessing code for testing set so that we can verify the testing result reported in the paper?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.