Code Monkey home page Code Monkey logo

cornet's Introduction

CORnet: Modeling the Neural Mechanisms of Core Object Recognition

What is this?

A family of simple yet powerful deep neural networks for visual neuroscience. What makes CORnets useful:

  • Simple
  • Lightweight
  • Recurrent
  • State-of-the-art on predicting primate neural and behavioral responses Brain-Score

read more...

Brought to you with from DiCarlo Lab @ MIT.

Available Models

(Click on model names to download the weights of ImageNet-trained models. Note that you do not need to download the weights manually: we use PyTorch Model Zoo to download the weights automatically.)

Name Description
CORnet-Z Our smallest, fastest model. Good neural fits
CORnet-RT Recurrent version of CORnet-Z. Better than CORnet-Z + recurrent but slow
CORnet-S CORnet-R with ResNet-like blocks. Best overall but slow to train

Note: In the past, we provided a model called CORnet-R. However, we found out that CORnet-R was not doing a biological temporal unrolling as described in the pre-print (Fig. 2, right). Instead, it was performing a non-biological unrolling (Fig. 2, left). We therefore issued a corrected version of the model but in order to avoid confusion, we labeled the biologically-unrolled version as CORnet-RT (that is, CORnet-RT is what is labeled in the pre-print as CORnet-R). We encourage to use CORnet-RT instead of CORnet-R, which is only provided as a legacy version in case you were already running experiments on it. In our experiments, we did not see major differences between the two models.

Quick Start

Want to test on your own images?

python run.py test --model S --data_path <path to your image folder> --output_path <path where you want output features saved>

Model weights will be automatically downloaded and restored.

Add -o <path to save features> if you want model responses to be saved someplace.

Add --ngpus 1 if you want to run this on a GPU.

Want to train on ImageNet?

  1. You need one or two GPUs. We used Titan X, nowadays a popular choice is GeForce GTX 1080 Ti or GeForce RTX 2080 Ti.

  2. Get ImageNet if you don't have it yet. If you do, note that validation images need to be put in separate folders, just like train data. Follow the instructions in that link to do so easily.

  3. You are ready to train:

  • CORnet-Z: python run.py train --model Z --workers 20 --ngpus 1 --step_size 10 --epochs 25 --lr .01 --data_path <path to imagenet> --output_path <path to saving trained model> (~20 hours)
  • CORnet-RT: python run.py train --model RT --workers 20 --ngpus 2 --step_size 10 --epochs 25 --lr .1 --data_path <path to imagenet> --output_path <path to saving trained model>
  • CORnet-S: python run.py train --model S --workers 20 --ngpus 2 --step_size 20 --epochs 43 --lr .1 --data_path <path to imagenet> --output_path <path to saving trained model> (several days)

If installation is needed

pip install git+https://github.com/dicarlolab/CORnet

Details

Longer Motivation

Deep artificial neural networks with spatially repeated processing (aka, deep convolutional ANNs) have been established as the best class of candidate models of visual processing in primate ventral visual processing stream. Over the past five years, these ANNs have evolved from a simple feedforward eight-layer architecture in AlexNet to extremely deep and branching NASNet architectures, demonstrating increasingly better object categorization performance and increasingly better explanatory power of both neural and behavioral responses. However, from the neuroscientist's point of view, the relationship between such very deep architectures and the ventral visual pathway is incomplete in at least two ways. On one hand, current state-of-the-art ANNs appear to be too complex (e.g. now over 100 levels) compared with the relatively shallow cortical hierarchy (4-8 levels), which makes it difficult to map their elements to those in the ventral visual stream and makes it difficult to understand what they are doing. On the other hand, current state-of-the-art ANNs appear to be not complex enough in that they lack recurrent connections and the resulting neural response dynamics that are commonplace in the ventral visual stream. Here we describe our ongoing efforts to resolve both of these issues by developing a "CORnet" family of deep neural network architectures. Rather than just seeking high object recognition performance (as the state-of-the-art ANNs above), we instead try to reduce the model family to its most important elements (CORnet-Z) and then gradually build new ANNs with recurrent and skip connections while monitoring both performance and the match between each new CORnet model and a large body of primate brain and behavioral data. We report here that our current best ANN model derived from this approach (CORnet-S) is among the top models on Brain-Score, a composite benchmark for comparing models to the brain, but is simpler than other deep ANNs in terms of the number of convolutions performed along the longest path of information processing in the model. All CORnet models are available at github.com/dicarlolab/CORnet, and we plan to update this manuscript and the available models in this family as they are produced.

Read more: Kubilius*, Schrimpf*, et al. (NeurIPS, 2019)

Requirements

  • Python 3.6+
  • PyTorch 0.4.1+
  • numpy
  • pandas
  • tqdm
  • fire

License

GNU GPL 3+

FAQ

  • Is CORnet-S the model of vision?

No. This is a constant work in progress. We display here our best current models for core object recognition but these models are constantly evolving.

  • Why not "CoreNet"?

COR = Core Object Recognition. Also, CORnet has a nice connection to "cortex".

  • My model is better than CORnet. Can I place it in this repository?

Exciting. Find a nice name for it and submit it to Brain-Score.org. This repository is only for CORnet family of models, while Brain-Score is a great place to show your model to the world and link to its own repository.

  • Are hyperparameters arbitrary?

No. We tried many architectures and these are the ones that worked best. However, an exhaustive search has not been done. Simpler yet equally good models might exist, as well as more complicated but more predictive models.

  • Why do you use classes for defining everything? Aren't functions enough?

Classes allow packaging functions into a single object, providing a good code organization.

Citation

For CORnet-S:

Kubilius, J., Schrimpf, M., Kar, K., Rajalingham, R., Hong, H., Majaj, N., ... & Dicarlo, J. (2019). Brain-like object recognition with high-performing shallow recurrent ANNs. In Advances in Neural Information Processing Systems (pp. 12785-12796).

@inproceedings{KubiliusSchrimpf2019CORnet,
abstract = {Deep convolutional artificial neural networks (ANNs) are the leading class of candidate models of the mechanisms of visual processing in the primate ventral stream. While initially inspired by brain anatomy, over the past years, these ANNs have evolved from a simple eight-layer architecture in AlexNet to extremely deep and branching architectures, demonstrating increasingly better object categorization performance, yet bringing into question how brain-like they still are. In particular, typical deep models from the machine learning community are often hard to map onto the brain's anatomy due to their vast number of layers and missing biologically-important connections, such as recurrence. Here we demonstrate that better anatomical alignment to the brain and high performance on machine learning as well as neuroscience measures do not have to be in contradiction. We developed CORnet-S, a shallow ANN with four anatomically mapped areas and recurrent connectivity, guided by Brain-Score, a new large-scale composite of neural and behavioral benchmarks for quantifying the functional fidelity of models of the primate ventral visual stream. Despite being significantly shallower than most models, CORnet-S is the top model on Brain-Score and outperforms similarly compact models on ImageNet. Moreover, our extensive analyses of CORnet-S circuitry variants reveal that recurrence is the main predictive factor of both Brain-Score and ImageNet top-1 performance. Finally, we report that the temporal evolution of the CORnet-S "IT" neural population resembles the actual monkey IT population dynamics. Taken together, these results establish CORnet-S, a compact, recurrent ANN, as the current best model of the primate ventral visual stream.},
archivePrefix = {arXiv},
arxivId = {1909.06161},
author = {Kubilius, Jonas and Schrimpf, Martin and Hong, Ha and Majaj, Najib J. and Rajalingham, Rishi and Issa, Elias B. and Kar, Kohitij and Bashivan, Pouya and Prescott-Roy, Jonathan and Schmidt, Kailyn and Nayebi, Aran and Bear, Daniel and Yamins, Daniel L. K. and DiCarlo, James J.},
booktitle = {Neural Information Processing Systems (NeurIPS)},
editor = {Wallach, H. and Larochelle, H. and Beygelzimer, A. and D'Alch{\'{e}}-Buc, F. and Fox, E. and Garnett, R.},
pages = {12785----12796},
publisher = {Curran Associates, Inc.},
title = {{Brain-Like Object Recognition with High-Performing Shallow Recurrent ANNs}},
url = {http://papers.nips.cc/paper/9441-brain-like-object-recognition-with-high-performing-shallow-recurrent-anns},
year = {2019}
}

For CORnet-Z and CORnet-RT:

Kubilius, J., Schrimpf, M., Nayebi, A., Bear, D., Yamins, D.L.K., DiCarlo, J.J. (2018) CORnet: Modeling the Neural Mechanisms of Core Object Recognition. biorxiv. doi:10.1101/408385

cornet's People

Contributors

eliulm avatar mschrimpf avatar qbilius 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

cornet's Issues

Error when running test on CPU

The run script is failing when I don't specify the number of GPUs.

python run.py test --model S --data_path images --output_path features

Here's the stack trace:

Traceback (most recent call last):
  File "C:/Users/deral/University/Thesis/CORnet/run.py", line 350, in <module>
    fire.Fire(command=FIRE_FLAGS)
  File "C:\Users\deral\Anaconda3\envs\PyThesis\lib\site-packages\fire\core.py", line 138, in Fire
    component_trace = _Fire(component, args, parsed_flag_args, context, name)
  File "C:\Users\deral\Anaconda3\envs\PyThesis\lib\site-packages\fire\core.py", line 471, in _Fire
    target=component.__name__)
  File "C:\Users\deral\Anaconda3\envs\PyThesis\lib\site-packages\fire\core.py", line 675, in _CallAndUpdateTrace
    component = fn(*varargs, **kwargs)
  File "C:/Users/deral/University/Thesis/CORnet/run.py", line 226, in test
    model(im)
  File "C:\Users\deral\Anaconda3\envs\PyThesis\lib\site-packages\torch\nn\modules\module.py", line 532, in __call__
    result = self.forward(*input, **kwargs)
  File "C:\Users\deral\Anaconda3\envs\PyThesis\lib\site-packages\torch\nn\modules\container.py", line 100, in forward
    input = module(input)
  File "C:\Users\deral\Anaconda3\envs\PyThesis\lib\site-packages\torch\nn\modules\module.py", line 532, in __call__
    result = self.forward(*input, **kwargs)
  File "C:\Users\deral\Anaconda3\envs\PyThesis\lib\site-packages\torch\nn\modules\container.py", line 100, in forward
    input = module(input)
  File "C:\Users\deral\Anaconda3\envs\PyThesis\lib\site-packages\torch\nn\modules\module.py", line 532, in __call__
    result = self.forward(*input, **kwargs)
  File "C:\Users\deral\Anaconda3\envs\PyThesis\lib\site-packages\torch\nn\modules\conv.py", line 345, in forward
    return self.conv2d_forward(input, self.weight)
  File "C:\Users\deral\Anaconda3\envs\PyThesis\lib\site-packages\torch\nn\modules\conv.py", line 342, in conv2d_forward
    self.padding, self.dilation, self.groups)
RuntimeError: Expected object of device type cuda but got device type cpu for argument #1 'self' in call to _thnn_conv2d_forward

Process finished with exit code 1

I try to debug the execution and I found that the checkpoint data is loaded correctly. At line

ckpt_data = torch.utils.model_zoo.load_url(url, map_location=map_location)
the weights in state_dict have their device correctly set to cpu. However, after load_state_dict is called, the weights in the model have their device set to cuda:0. Could the problem be there?

A litter question about CORblock_S

I think the key point of this paper is that the CORblock_S can be learned for serval times in the one epoch.
So, how can you guarantee the conv2d in each for-loop is always the same one?
In my experience, when building a network using such a for-loop, all convolutions will with different weights.
It is equivalent to building a relatively long ordinary network.

CORnet doesn't complain but doesn't do anything either

Hey guys,

When I try to run the model out of the box nothing happens. I have realized that it works on some stimulus sets but not others. I figured this had to do with the images I want to get features being grayscale with only 1 channel. I modified them to have 3 identical channels but all I get is this, with my output path being empty. Any idea what the issue is? My apologies I'm new to all this!

issueScrnshot

CORnet inconsistent vector length

Disclaimer: I do not know whether this is an issue with CORnet or with the THINGSvision wrapper for CORnet (see: https://github.com/ViCCo-Group/THINGSvision).

When running images through CORnet-z, the output layer for IT, as far as I understand from the CORnet preprint, is supposed to be 7x7x512 which when flattened would be a vector of length 25088. This is indeed what happens when apply_center_crop is set to True. However, when it is set to False, the output vectors of the same images (224 x 224 pixels), same layer/module, end up being of size 32768. This behavior does not appear to be layer specific, I e.g. also tested it for the V1 output layer and the vector length also depends on whether center crop is applied or not.

I am not quite sure if this is a bug or "normal" behavior that I then just do not quite understand.

Where's the comments?

Who wrote this? Definitely not some sort of "real" software engineer. You call this MIT work.

Before you tell me to do this myself, look in the mirror and remove the GPL license and replace with MIT license.

CORnet-R and CORnet-RT give the same activations for all images - IT output

I'm running this on Windows 10. I have run all 4 networks on multiple image sets and CORnets R and RT give the same activation values for all images in each set when the layer is 'IT' and the sublayer is 'output'. In other words, it's like nothing is being computed - the unit activations just stay the same and are repeated for the number of images in the stimulus set. Moreover, this is true across sets too, you just get the same 1x25088 vector repeated over and over. I'm executing it with the command:

python run.py test --model R --data_path Images/500Stimuli --output_path features/500Stimuli

Any insight as to what I'm doing wrong? This is not true of CORnets-Z or S. I notice that those are written differently (Class CORBlock_Z/S and a method def CORnet-Z/S as opposed to two classes CORblock_R/RT and CORnet_R/RT), is there a detail for how to run this I'm missing? Apologies for the multiple issues!

TypeError: can't convert CUDA tensor to numpy.

Hello,

I tried to make a simple test with one image. Following the instruction I run:

python run.py test --model S --data_path images --output_path features --ngpus=1

The script is failing with on both windows and linux:

TypeError: can't convert CUDA tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first

Here's my conda environment:

python 3.7.6
pandas 1.0.1
pytorch 1.4.0
numpy 1.18.1

I will be investigating on a solution for this, but I was wondering whether you've already some insight on the problem. Have the modules been tested with a more recent version of PyTorch? Thanks!

How to get Brain-Score?

After I get the output features of test image (eg. CORnet-S_decoder_avgpool_feats.npy), how to get the Brain-Score. Can you show me the detailed steps? Thanks.

training Z slow

I'm training CORnet-Z on a Titan X with 20 workers. One epoch takes about 5 hours which is way too long (i.e. cannot train the whole thing in 28 hours).

fire complains despite success

Run command: python run.py test --restore_path cornet_z_epoch25.pth.tar - --model Z --data_path my_images -o .

Output:

100%|██████████| 136/136 [00:04<00:00, 30.35it/s]
Fire trace:
1. Initial component
2. Accessed property "test"
3. Called routine "test" (/Users/apurvaratanmurty/dev/CORnet/run.py:187)
4. ('Could not consume arg:', '--model')

Type:        NoneType
String form: None

Usage:       run.py test --restore_path cornet_z_epoch25.pth.tar -

However, the features file was created successfully.

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.