Code Monkey home page Code Monkey logo

few-shot-gnn's People

Contributors

sweetyvictor avatar vgsatorras avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

few-shot-gnn's Issues

Questions about the model saving and the test after training

Dear author

Thanks for sharing your code. I learned a lot from it. But I have two confusions about the experiment for 5way 1shot under mini-imagenet.

1.the first is about the save interval you used in experiments. If you use save interval as default = 300000, when you finished experiment, you will not save any models. How can I save the parameters of the models?

2.After 80,000 iterations of training, why not use the model parameters with the highest accuracy on the validation set but use the 80,000th model parameters for test after training?

get_task_batch with batch_size 40 returns batch_x which has around 28 different classes

Hi, I am a bit confused by the data obtained from train_loader.get_task_batch. When I look into the label_x_global values in 1 case I get around 28 different classes and so label_x actually marks different classes by the same class number (out of say way=5).
Maybe I am getting this wrong but can you explain the significance of batch size (does not seem to be related to shot or way or shot*way) and how you are preparing the batches and how are you using different classes by the same class number in the same iteration.

About the last layer of GNN

Thanks for sharing the code, I have a question about the last layer of GNN.
As the code, the output dim of the last layer of GNN is the number of training category C (such as C-way-K-shot). I think the last layer of GNN is equivalent to the classification layer (such as the last fc layer of a classification network). However, this layer is fixed when testing. Shouldn't there be different classification layer for different tasks? I am very confused why you fixed the last layer of GNN in your network.

ValueError: incorrect size: only supporting singleton expansion (size=1)

Traceback (most recent call last):
File "main.py", line 223, in
train()
File "main.py", line 157, in train
data=[batch_x, label_x, batches_xi, labels_yi, oracles_yi, hidden_labels])
File "main.py", line 97, in train_batch
out_metric, out_logits = metric_nn(inputs=[z, zi_s, labels_yi, oracles_yi, hidden_labels])
File "/home/lb/anaconda2/envs/python36/lib/python3.6/site-packages/torch/nn/modules/module.py", line 206, in call
result = self.forward(*input, **kwargs)
File "/home/lb/few-shot-gnn/models/models.py", line 170, in forward
return self.gnn_iclr_forward(z, zi_s, labels_yi)
File "/home/lb/few-shot-gnn/models/models.py", line 136, in gnn_iclr_forward
logits = self.gnn_obj(nodes).squeeze(-1)
File "/home/lb/anaconda2/envs/python36/lib/python3.6/site-packages/torch/nn/modules/module.py", line 206, in call
result = self.forward(*input, **kwargs)
File "/home/lb/few-shot-gnn/models/gnn_iclr.py", line 209, in forward
Wi = self._modules['layer_w{}'.format(i)](x, W_init)
File "/home/lb/anaconda2/envs/python36/lib/python3.6/site-packages/torch/nn/modules/module.py", line 206, in call
result = self.forward(*input, **kwargs)
File "/home/lb/few-shot-gnn/models/gnn_iclr.py", line 109, in forward
W_new = W_new - W_id.expand_as(W_new) * 1e8
File "/home/lb/anaconda2/envs/python36/lib/python3.6/site-packages/torch/autograd/variable.py", line 652, in expand_as
return Expand(tensor.size())(self)
File "/home/lb/anaconda2/envs/python36/lib/python3.6/site-packages/torch/autograd/_functions/tensor.py", line 115, in forward
result = i.expand(*self.sizes)
File "/home/lb/anaconda2/envs/python36/lib/python3.6/site-packages/torch/tensor.py", line 261, in expand
raise ValueError('incorrect size: only supporting singleton expansion (size=1)')
ValueError: incorrect size: only supporting singleton expansion (size=1)
Hello, this is the problem when I run your code , can you help me solve it...

some code maybe error?

hi,
Thanks for sharing your code. I learned a lot from it.
However, I think the line 82 in /models/models.py, which is that

self.bn_fc = nn.BatchNorm2d(self.emb_size)

maybe change into self.bn_fc = nn.BatchNorm1d(self.emb_size)

I am not sure if it is correct,and I hope to discuss together

thanks

About the initial label fields of the query node and J2

The initial label field of query node is filled with zero in gnn_iclr_nl mode
https://github.com/vgsatorras/few-shot-gnn/blob/master/models/models.py#L125
the initial label field of query node is filled with 1/K in gnn_iclr_active mode
https://github.com/vgsatorras/few-shot-gnn/blob/master/models/models.py#L143
Another question is why J2 is adopted rather than just W_id + W_new?
https://github.com/vgsatorras/few-shot-gnn/blob/master/models/gnn_iclr.py#L131
Thank you

Code for multiple shots during testing

Hi there,

test_N_shots in main.py doesn't seem to set the number of shots during testing and only test_one_shot() is implemented in test.py. Is the code incomplete or I'm not understanding the implementation correctly? Thanks!

how to train without the trick of rotation?

def load_dataset(self, train, size):
    print("Loading dataset")
    if train:
        with open(os.path.join(self.root, 'compacted_datasets', 'omniglot_train.pickle'), 'rb') as handle:
            data = pickle.load(handle)
            print('data为{}'.format(data.keys()))
    else:
        with open(os.path.join(self.root, 'compacted_datasets', 'omniglot_test.pickle'), 'rb') as handle:
            data = pickle.load(handle)
    print("Num classes before rotations: "+str(len(data)))
    ”“”
    data_rot = {}
    # resize images and normalize
    # print('data的类型是{}'.format(type(data)))
    # print('data.keys()是是{}'.format(data.keys()))
    # print('len(data[5])是{}'.format(len(data[5])))
    for class_ in data:
        # print('class_为{}'.format(class_))
        for rot in range(4):
            data_rot[class_ * 4 + rot] = []
            for i in range(len(data[class_])):
                image2resize = pil_image.fromarray(np.uint8(data[class_][i]*255))
                image_resized = image2resize.resize((size[1], size[0]))
                image_resized = np.array(image_resized, dtype='float32')/127.5 - 1
                image = self.rotate_image(image_resized, rot)
                image = np.expand_dims(image, axis=0)
                data_rot[class_ * 4 + rot].append(image)
    # print('data_rot的keys为{}'.format(data_rot.keys()))
    print("Dataset Loaded")
    print("Num classes after rotations: "+str(len(data_rot)))
    self.sanity_check(data_rot)
    “”“
    return data

I commented out the data enhancement part directly. But there are some dimensional matching errors.
I would be very grateful if you can help me solve it. thank you!

get_task_batch function from Generator

for batch_counter in range(batch_size):
positive_class = random.randint(0, n_way - 1)

        # Sample random classes for this TASK
        classes_ = list(self.data.keys())
        sampled_classes = random.sample(classes_, n_way)
        indexes_perm = np.random.permutation(n_way * num_shots)

        counter = 0
        for class_counter, class_ in enumerate(sampled_classes):
            if class_counter == positive_class:
                # We take num_shots + one sample for one class
                samples = random.sample(self.data[class_], num_shots+1)
                # Test sample is loaded
                batch_x[batch_counter, :, :, :] = samples[0]
                labels_x[batch_counter, class_counter] = 1
                labels_x_global[batch_counter] = self.class_encoder[class_]
                samples = samples[1::]
            else:
                samples = random.sample(self.data[class_], num_shots)

Why we need positive class ? What is the meaning of indexes perm ?and why we set labels_x[batch_counter, class_counter] = 1 by class_counter instead of using class_?

Thanks,

the problem of the paper reproduction

Dear author,
We would like to quote your article. We would like to reproduce your results in active learning.
The results are slightly different. Can you tell us what went wrong?
The running configuration I used for your paper is as follows:
EXPNAME=minimagenet_N5_S1_U4
CUDA_VISIBLE_DEVICES=3 python3 main.py --exp_name $EXPNAME --dataset mini_imagenet --test_N_way 5 --train_N_way 5 --train_N_shots 5 --test_N_shots 5 --unlabeled_extra 4 --batch_size 40 --dec_lr=15000 --iterations 100000 --dataset_root /data/jasmine --metric_network gnn_iclr_active
The result in your paper is as follows:
Method 5-Way 5-shot 20%-labeled
GNN - AL 55.99% 1.35%
GNN - Random 52.56% 1.18%
The result in our experment is as follows:
**** TESTING WITH val ***
Loading dataset
Num classes 16
Num images 9600
514 correct from 1000 Accuracy: 51.400%)
1041 correct from 2000 Accuracy: 52.050%)
1569 correct from 3000 Accuracy: 52.300%)
2090 correct from 4000 Accuracy: 52.250%)
2595 correct from 5000 Accuracy: 51.900%)
3118 correct from 6000 Accuracy: 51.967%)
3646 correct from 7000 Accuracy: 52.086%)
4161 correct from 8000 Accuracy: 52.013%)
4692 correct from 9000 Accuracy: 52.133%)
5201 correct from 10000 Accuracy: 52.010%)
5723 correct from 11000 Accuracy: 52.027%)
6239 correct from 12000 Accuracy: 51.992%)
6742 correct from 13000 Accuracy: 51.862%)
7243 correct from 14000 Accuracy: 51.736%)
7752 correct from 15000 Accuracy: 51.680%)
7752 correct from 15000 Accuracy: 51.680%)
*** TEST FINISHED ***

**** TESTING WITH test ***
Loading dataset
Num classes 20
Num images 12000
512 correct from 1000 Accuracy: 51.200%)
1065 correct from 2000 Accuracy: 53.250%)
1593 correct from 3000 Accuracy: 53.100%)
2110 correct from 4000 Accuracy: 52.750%)
2630 correct from 5000 Accuracy: 52.600%)
3151 correct from 6000 Accuracy: 52.517%)
3670 correct from 7000 Accuracy: 52.429%)
4183 correct from 8000 Accuracy: 52.288%)
4693 correct from 9000 Accuracy: 52.144%)
5212 correct from 10000 Accuracy: 52.120%)
5759 correct from 11000 Accuracy: 52.355%)
6292 correct from 12000 Accuracy: 52.433%)
6813 correct from 13000 Accuracy: 52.408%)
7334 correct from 14000 Accuracy: 52.386%)
7858 correct from 15000 Accuracy: 52.387%)
7858 correct from 15000 Accuracy: 52.387%)
*** TEST FINISHED ***

**** TESTING WITH train ***
Loading dataset
Num classes 64
Num images 38400
751 correct from 1000 Accuracy: 75.100%)
1464 correct from 2000 Accuracy: 73.200%)
2195 correct from 3000 Accuracy: 73.167%)
2195 correct from 3000 Accuracy: 73.167%)
*** TEST FINISHED ***

Best test accuracy 51.9667

**** TESTING WITH test ***
Loading dataset
Num classes 20
Num images 12000
538 correct from 1000 Accuracy: 53.800%)
1062 correct from 2000 Accuracy: 53.100%)
1578 correct from 3000 Accuracy: 52.600%)
2077 correct from 4000 Accuracy: 51.925%)
2603 correct from 5000 Accuracy: 52.060%)
3134 correct from 6000 Accuracy: 52.233%)
3655 correct from 7000 Accuracy: 52.214%)
4217 correct from 8000 Accuracy: 52.712%)
4744 correct from 9000 Accuracy: 52.711%)
5241 correct from 10000 Accuracy: 52.410%)
5800 correct from 11000 Accuracy: 52.727%)
6341 correct from 12000 Accuracy: 52.842%)
6886 correct from 13000 Accuracy: 52.969%)
7417 correct from 14000 Accuracy: 52.979%)
7939 correct from 15000 Accuracy: 52.927%)
8452 correct from 16000 Accuracy: 52.825%)
8970 correct from 17000 Accuracy: 52.765%)
9519 correct from 18000 Accuracy: 52.883%)
10079 correct from 19000 Accuracy: 53.047%)
10605 correct from 20000 Accuracy: 53.025%)
11132 correct from 21000 Accuracy: 53.010%)
11648 correct from 22000 Accuracy: 52.945%)
12187 correct from 23000 Accuracy: 52.987%)
12694 correct from 24000 Accuracy: 52.892%)
13229 correct from 25000 Accuracy: 52.916%)
13733 correct from 26000 Accuracy: 52.819%)
14232 correct from 27000 Accuracy: 52.711%)
14733 correct from 28000 Accuracy: 52.618%)
15250 correct from 29000 Accuracy: 52.586%)
15767 correct from 30000 Accuracy: 52.557%)
15767 correct from 30000 Accuracy: 52.557%)
*** TEST FINISHED ***

imagenet dataset issue

For the mini_imagenet dataset, after the images are inflated the program terminates automatically when counter reaches 60000 count

Question about the number of testing data

Hi, It's a very nice work!
I don't understand the division of data volume when testing,
for example, in the mini-imagenet dataset, the images num is 12000, but when 'TEST WITH test', you load 15000 images
the same question with 'val dataset'
why set like this num,
Looking forward to your reply !

Puzzles about the number of train data

Thanks for sharing the code, I have learned a lot from it. But I am puzzled about the train data.

for i in range(n_way*num_shots):
batches_xi.append(np.zeros((batch_size, self.input_channels, self.size[0], self.size[1]), dtype='float32'))
labels_yi.append(np.zeros((batch_size, n_way), dtype='float32'))
oracles_yi.append(np.zeros((batch_size, n_way), dtype='float32'))

In the code above, when we increase the batch_size, will the total total train data we used for training be increased?Since the iteration number is setted before training and the size of batches_xi is (n_way*num_shots,batch_size,input_channels,size[0],size[1]).

Questions about parameters named "nf" and "J" in the model GNN_nl

Thanks a lot for sharing the code.
I feel confused when I was reading the code about class GNN_nl in "./models/gnn_iclr".What are the specific meanings of these two parameters “nf” and "J"? And what should I pay attention to when setting these two parameters?
Thank you.

Puzzles about the W_init

Thanks for sharing your code. I learned a lot from it.
I have a question when I was reading the line 204 in /models/gnn_iclr.py

W_init = Variable(torch.eye(x.size(1)).unsqueeze(0).repeat(x.size(0), 1, 1).unsqueeze(3))

Why is the initialization of W_init as the identity matrix? Is it because of the nodes in the graph self-loops?

Confusions about architecture of GNN

Hi Victor,

after inspecting the codes, I have some confusions about the architecture of the GNN you used.

That is, the features of the intermediate layer are obtained by concatenating the input features and the transformed features which have d^{k+1} = d^{k-1} + #nf by x = torch.cat([x, x_new], 2), instead of directly being transformed to the features with d^{k+1}.

This way is little different to other GNN, where the direct transformation is used and you didn't mention this in the paper. I am wondering, if you designed this on purpose and why you construct the GNN like this.

Adaptation phase during testing

Hi there,

I'd like to ask which part of the code is responsible for the adaptation phase during testing. From what I understand, test.test_one_shot(...) is responsible for testing but I don't see any "n-shot training/adaptation" within that function. Thanks!

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.