{ "cells": [ { "cell_type": "markdown", "id": "competent-surrey", "metadata": {}, "source": [ "## Neural Population Control\n", "#### Pipeline for roi and testing the encoding models, performing in-silico ephys and generating the most-exciting images (MEIs)" ] }, { "cell_type": "markdown", "id": "adolescent-parish", "metadata": {}, "source": [ "Change below the constants that pertain to your experiment, such as names/dates/conditions, and setup info (pixels per degree):" ] }, { "cell_type": "code", "execution_count": 1, "id": "short-postage", "metadata": {}, "outputs": [], "source": [ "import npc\n", "import numpy as np\n", "import math\n", "\n", "# data-constants:\n", "monkey_names = ['monkeyF','monkeyF','monkeyF','monkeyF','monkeyF','monkeyF','monkeyF','monkeyF',\n", " 'monkeyF','monkeyF','monkeyF','monkeyF','monkeyF','monkeyF','monkeyF','monkeyF']\n", "roi_names = ['1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16']\n", "gen_path = '/media/stijn/2bb74e85-3681-4561-88b7-abd98482de61/paolo/Data/'\n", "\n", "# layers for traning and testing:\n", "# 'False' on top will run the grid-search first and then stop\n", "# 'True' on top will run the grid-search first and then will train the best layer\n", "layers = ['False',\n", " 'conv2d1',\n", " 'conv2d2',\n", " 'mixed3a',\n", " 'mixed3b',\n", " 'mixed4a',\n", " 'mixed4b',\n", " 'mixed4c',\n", " 'mixed4d',\n", " 'mixed4e',\n", " 'mixed5a',\n", " 'mixed5b']\n", "\n", "\n", "# constants for mei generation:\n", "seed = 0\n", "pixperdeg = 25.92\n", "stim_size = 500\n", "mask_size = 128\n", "shift_x = 100\n", "shift_y = 100" ] }, { "cell_type": "code", "execution_count": 1, "id": "ceramic-white", "metadata": {}, "outputs": [], "source": [ "import npc\n", "import numpy as np\n", "import math\n", "\n", "# data-constants:\n", "monkey_names = ['monkeyN']\n", "roi_names = ['transient_IT']\n", "gen_path = '/media/stijn/2bb74e85-3681-4561-88b7-abd98482de61/paolo/Data/'\n", "\n", "# layers for traning and testing:\n", "# 'False' on top will run the grid-search first and then stop\n", "# 'True' on top will run the grid-search first and then will train the best layer\n", "layers = ['False',\n", " 'conv2d1',\n", " 'conv2d2',\n", " 'mixed4e']\n", "\n", "\n", "# constants for mei generation:\n", "seed = 0\n", "pixperdeg = 25.92\n", "stim_size = 500\n", "mask_size = 128\n", "shift_x = 100\n", "shift_y = 100" ] }, { "cell_type": "markdown", "id": "wrong-radio", "metadata": {}, "source": [ "Perform the data formatting and train the models:" ] }, { "cell_type": "code", "execution_count": null, "id": "metropolitan-zimbabwe", "metadata": {}, "outputs": [], "source": [ "### extract the data and train all the models\n", "# it'll take a lot of time!\n", "for monkey_name, roi in zip(monkey_names, roi_names):\n", " !python3 extract_data.py $gen_path $monkey_name $roi\n", " for layer in layers:\n", " !CUDA_VISIBLE_DEVICES=0 python3 train_neural_model.py $gen_path $monkey_name $roi $layer $layers" ] }, { "cell_type": "markdown", "id": "downtown-restoration", "metadata": {}, "source": [ "Finally, compute the MEIs and the properties of each neuron:" ] }, { "cell_type": "code", "execution_count": null, "id": "turned-laser", "metadata": {}, "outputs": [], "source": [ "# plot and save the modeled RFs and MEIs:\n", "for monkey_name, roi in zip(monkey_names, roi_names):\n", " print('======================')\n", " print('Processing: ' + monkey_name + ', ' + roi)\n", " if roi != '':\n", " roi = '_' + roi\n", " all_corrs,layer = npc.plot_layer_corrs(gen_path,monkey_name,layers[1:],roi)\n", " monkey_model,n_neurons = npc.load_trained_model(gen_path,monkey_name,roi,layer)\n", " corrs = npc.compute_val_corrs(gen_path,monkey_name,monkey_model,roi)\n", " goods,all_good_rfs = npc.good_neurons(monkey_model,n_neurons,corrs,make_plots=False)\n", " #all_corrs = []\n", " _ = npc.gaussian_RFs(gen_path,all_good_rfs,goods,corrs,all_corrs,pixperdeg,stim_size,mask_size,monkey_model,monkey_name,roi,shift_x,shift_y)\n", " npc.generate_MEIS(gen_path,monkey_model,monkey_name,goods,roi)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.9" } }, "nbformat": 4, "nbformat_minor": 5 }