Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions cellprediction/Predict_cell_fates.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"To predict cell fates using our approach, we need the `caffe` framework (to extract features) as well as `Theano` (to do the acutal prediction). To install caffe, first clone our fork from [here](https://github.com/flophys/caffe) (providing full support for concatenation layer). Then follow stanard `caffe` installation instructions that can be found [here](http://caffe.berkeleyvision.org/installation.html). `Theano` can be installed following the instructions detailed [here](http://deeplearning.net/software/theano/install.html). We recommend using the Anaconda distribution for an easy installation process of both `Theano` and `caffe`.\n",
"Predictions are not computationally expensive and can be performed using CPU on a standard laptop (no cuda/GPU requiured to run this notebook)."
"To predict cell fates using our approach, we need the `caffe` framework (to extract features) as well as `Theano` (to do the actual prediction). To install caffe, first clone our fork from [here](https://github.com/flophys/caffe) (providing full support for concatenation layer). Then follow standard `caffe` installation instructions that can be found [here](http://caffe.berkeleyvision.org/installation.html). `Theano` can be installed following the instructions detailed [here](http://deeplearning.net/software/theano/install.html). We recommend using the Anaconda distribution for an easy installation process of both `Theano` and `caffe`.\n",
"Predictions are not computationally expensive and can be performed using CPU on a standard laptop (no cuda/GPU required to run this notebook)."
]
},
{
Expand Down Expand Up @@ -51,6 +51,8 @@
"import sys\n",
"import pickle\n",
"from sklearn import metrics\n",
"if sys.version_info >= (3,): # python 3 compatibility\n",
" from importlib import reload\n",
"\n",
"caffe_root = '/Users/flo/software/caffe/' #root directory of the caffe installation\n",
"sys.path.append(caffe_root + 'python')\n",
Expand Down Expand Up @@ -134,7 +136,7 @@
}
],
"source": [
"film_tr = \"120602PH5\"\n",
"film_tr = \"round_3\"\n",
"\n",
"PRETRAINED = './models/cnn_models/'+film_tr+'/trained_CNN.caffemodel' #path to the pretrained model\n",
"MODEL_FILE = os.path.join('./models/cnn_models/','CNN_deploy.prototxt') #model file specifying the architecture \n",
Expand All @@ -151,9 +153,7 @@
" labels.append(ims['label'][i])\n",
" predsCNN.append(res['pred_all'].mean())\n",
" if SP.mod(i+1,50)==0 or (i+1)==(nCells):\n",
" print('%i/%i cells processed' % (i+1,nCells))\n",
"\n",
"\n"
" print('%i/%i cells processed' % (i+1,nCells))\n"
]
},
{
Expand All @@ -179,11 +179,14 @@
}
],
"source": [
"fn = './models/rnn_models/120602PH5/trained_modelRNN.pkl'#pre-trained model\n",
"fn = './models/rnn_models/round_3/trained_modelRNN.pkl'#pre-trained model\n",
"\n",
"#load model parameters\n",
"f = open(fn, 'rb')\n",
"[structure, weights] = pickle.load(f)\n",
"if sys.version_info >= (3,): # python 3 compatibility\n",
" [structure, weights] = pickle.load(f, encoding='latin1')\n",
"else:\n",
" [structure, weights] = pickle.load(f)\n",
"\n",
"#populate model\n",
"model = RNN(structure[0], structure[1], structure[2], 'dblstm')\n",
Expand Down Expand Up @@ -230,8 +233,7 @@
"F1 = metrics.f1_score(SP.vstack(labels).ravel().astype('int'),pred.ravel()>.5, average=\"macro\")\n",
"print('Macro averaged F1 score %1.2f:' % F1)\n",
"\n",
"extr.plotPerfromance(pred.ravel(), SP.vstack(labels).ravel())\n",
"\n"
"extr.plotPerfromance(pred.ravel(), SP.vstack(labels).ravel())"
]
},
{
Expand Down
20 changes: 14 additions & 6 deletions cellprediction/py/extract_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,20 @@ def extract(pretrained, model_file,input_image_test,displacement_test):
# feat
def load_pickle(pickle_file):

fpickle = open(pickle_file, 'r')
input_image = pickle.load(fpickle)
lab = pickle.load(fpickle)
mov = pickle.load(fpickle)
cellID = pickle.load(fpickle)
fpickle.close()
if sys.version_info >= (3,): # python 3 compatibility
fpickle = open(pickle_file, 'rb')
input_image = pickle.load(fpickle, encoding='latin1')
lab = pickle.load(fpickle, encoding='latin1')
mov = pickle.load(fpickle, encoding='latin1')
cellID = pickle.load(fpickle, encoding='latin1')
fpickle.close()
else:
fpickle = open(pickle_file, 'r')
input_image = pickle.load(fpickle)
lab = pickle.load(fpickle)
mov = pickle.load(fpickle)
cellID = pickle.load(fpickle)
fpickle.close()

res = {}
res['mov'] = mov
Expand Down