Skip to content

Commit bac09fb

Browse files
author
mannypaeza
committed
changes
1 parent 9532291 commit bac09fb

9 files changed

+420
-5180
lines changed

caiman/train/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#!/usr/bin/env python
22
import pkg_resources
33

4-
from caiman.train.train_cnn_model_keras import cnn_model_keras, save_model_keras, load_model_keras
5-
from caiman.train.train_cnn_model_pytorch import cnn_model_pytorch, train_test_split, train, validate, get_batch_accuracy, save_model_pytorch, load_model_pytorch
4+
from caiman.train.train_cnn_model_helper import cnn_model_pytorch, train_test_split, train, validate, get_batch_accuracy, save_model_pytorch, load_model_pytorch, cnn_model_keras, save_model_keras, load_model_keras
65

76
__version__ = pkg_resources.get_distribution('caiman').version

caiman/train/ground_truth_cnmf_seeded.ipynb

Lines changed: 97 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@
270270
"cell_type": "markdown",
271271
"metadata": {},
272272
"source": [
273-
"### Parameters for the Movie and Name of the Movie "
273+
"### Parameters for the Movie"
274274
]
275275
},
276276
{
@@ -292,7 +292,7 @@
292292
"cell_type": "markdown",
293293
"metadata": {},
294294
"source": [
295-
"## Analysis "
295+
"## Run Analysis"
296296
]
297297
},
298298
{
@@ -308,16 +308,30 @@
308308
"d1, d2 = dims\n",
309309
"images = np.reshape(Yr.T, [T] + list(dims), order='F')\n",
310310
"Y = np.reshape(Yr, dims + (T,), order='F')\n",
311-
"m_images = cm.movie(images)\n",
312-
"\n",
313-
"# correlation image\n",
311+
"m_images = cm.movie(images)"
312+
]
313+
},
314+
{
315+
"cell_type": "markdown",
316+
"metadata": {},
317+
"source": [
318+
"### Correlation Image"
319+
]
320+
},
321+
{
322+
"cell_type": "code",
323+
"execution_count": null,
324+
"metadata": {},
325+
"outputs": [],
326+
"source": [
314327
"if m_images.shape[0] < 10000:\n",
315328
" Cn = m_images.local_correlations(\n",
316329
" swap_dim=params_movie['swap_dim'], frames_per_chunk=1500)\n",
317330
" Cn[np.isnan(Cn)] = 0\n",
318331
"else:\n",
332+
" #Saved as a tif file\n",
319333
" Cn = np.array(cm.load(('/'.join(params_movie['gtname'][0].split('/')[:-2] + [\n",
320-
" 'projections', 'correlation_image_better.tif'])))).squeeze()\n",
334+
" 'projections', 'correlation_image_better.tif'])))).squeeze() \n",
321335
"\n",
322336
"plt.imshow(Cn, cmap='gray', vmax=.95)"
323337
]
@@ -338,8 +352,15 @@
338352
"\n",
339353
"print(radius)\n",
340354
"print(roi_cons.shape)\n",
341-
"pl.imshow(roi_cons.sum(0))\n",
342-
"\n",
355+
"plt.imshow(roi_cons.sum(0))"
356+
]
357+
},
358+
{
359+
"cell_type": "code",
360+
"execution_count": null,
361+
"metadata": {},
362+
"outputs": [],
363+
"source": [
343364
"if params_movie['kernel'] is not None: # kernel usually two\n",
344365
" kernel = np.ones(\n",
345366
" (radius // params_movie['kernel'], radius // params_movie['kernel']), np.uint8)\n",
@@ -349,24 +370,42 @@
349370
"\n",
350371
"A_in = np.reshape(roi_cons.transpose(\n",
351372
" [2, 1, 0]), (-1, roi_cons.shape[0]), order='C')\n",
352-
"pl.figure()\n",
373+
"plt.figure()\n",
353374
"crd = plot_contours(A_in, Cn, thr=.99999)"
354375
]
355376
},
377+
{
378+
"cell_type": "markdown",
379+
"metadata": {},
380+
"source": [
381+
"### Parameter Setting"
382+
]
383+
},
356384
{
357385
"cell_type": "code",
358386
"execution_count": null,
359387
"metadata": {},
360388
"outputs": [],
361389
"source": [
362-
"# %% some parameter settings\n",
363390
"# order of the autoregressive fit to calcium imaging in general one (slow gcamps) or two (fast gcamps fast scanning)\n",
364391
"p = params_movie['p']\n",
365392
"# merging threshold, max correlation allowed\n",
366-
"merge_thresh = params_movie['merge_thresh']\n",
367-
"\n",
368-
"# %% Extract spatial and temporal components on patches\n",
369-
"# TODO: todocument\n",
393+
"merge_thresh = params_movie['merge_thresh']"
394+
]
395+
},
396+
{
397+
"cell_type": "markdown",
398+
"metadata": {},
399+
"source": [
400+
"### Extract spatial and temporal components on patches"
401+
]
402+
},
403+
{
404+
"cell_type": "code",
405+
"execution_count": null,
406+
"metadata": {},
407+
"outputs": [],
408+
"source": [
370409
"if images.shape[0] > 10000:\n",
371410
" check_nan = False\n",
372411
"else:\n",
@@ -383,13 +422,17 @@
383422
"f = cnm.f\n",
384423
"snt = cnm.sn\n",
385424
"print(('Number of components:' + str(A.shape[-1])))\n",
386-
"# %%\n",
387-
"pl.figure()\n",
388-
"# TODO: show screenshot 12`\n",
389-
"# TODO : change the way it is used\n",
425+
"plt.figure()\n",
390426
"crd = plot_contours(A, Cn, thr=params_display['thr_plot'])"
391427
]
392428
},
429+
{
430+
"cell_type": "markdown",
431+
"metadata": {},
432+
"source": [
433+
"Threshold Components "
434+
]
435+
},
393436
{
394437
"cell_type": "code",
395438
"execution_count": null,
@@ -400,10 +443,9 @@
400443
"view_patches_bar(Yr, scipy.sparse.coo_matrix(A.tocsc()[:, :]), C[:, :], b, f, dims[0], dims[1],\n",
401444
" YrA=YrA[:, :], img=Cn)\n",
402445
"\n",
403-
"#%%\n",
404446
"c, dview, n_processes = cm.cluster.setup_cluster(\n",
405447
" backend='local', n_processes=None, single_thread=False)\n",
406-
"#%% thredshold components\n",
448+
"\n",
407449
"min_size_neuro = 3 * 2 * np.pi\n",
408450
"max_size_neuro = (2 * radius)**2 * np.pi\n",
409451
"A_thr = cm.source_extraction.cnmf.spatial.threshold_components(A.tocsc()[:, :].toarray(), dims, medw=None, thr_method='max', maxthr=0.2, nrgthr=0.99, extract_cc=True,\n",
@@ -415,37 +457,57 @@
415457
" & (size_neurons < max_size_neuro))[0]\n",
416458
"A_thr = A_thr[:, idx_size_neuro]\n",
417459
"print(A_thr.shape)\n",
418-
"#%%\n",
460+
"\n",
419461
"crd = plot_contours(scipy.sparse.coo_matrix(\n",
420462
" A_thr * 1.), Cn, thr=.99, vmax=0.35)\n",
421-
"#%%\n",
463+
"\n",
422464
"roi_cons = np.load(params_movie['gtname'][0])\n",
423465
"print(roi_cons.shape)\n",
424-
"pl.imshow(roi_cons.sum(0))\n",
425-
"#%% compare CNMF sedded with ground truth\n",
426-
"pl.figure(figsize=(30, 20))\n",
466+
"plt.imshow(roi_cons.sum(0))"
467+
]
468+
},
469+
{
470+
"cell_type": "markdown",
471+
"metadata": {},
472+
"source": [
473+
"### Compare CNMF Seeded with ground truth"
474+
]
475+
},
476+
{
477+
"cell_type": "code",
478+
"execution_count": null,
479+
"metadata": {},
480+
"outputs": [],
481+
"source": [
482+
"plt.figure(figsize=(30, 20))\n",
427483
"tp_gt, tp_comp, fn_gt, fp_comp, performance_cons_off = cm.base.rois.nf_match_neurons_in_binary_masks(roi_cons, A_thr[:, :].reshape([dims[0], dims[1], -1], order='F').transpose([2, 0, 1]) * 1., thresh_cost=.7, min_dist=10,\n",
428484
" print_assignment=False, plot_results=False, Cn=Cn, labels=['GT', 'Offline'])\n",
429-
"pl.rcParams['pdf.fonttype'] = 42\n",
485+
"plt.rcParams['pdf.fonttype'] = 42\n",
430486
"font = {'family': 'Myriad Pro',\n",
431487
" 'weight': 'regular',\n",
432488
" 'size': 20}\n",
433-
"pl.rc('font', **font)\n",
434-
"\n",
435-
"#%%\n",
436-
"np.savez(os.path.join(os.path.split(fname_new)[0], os.path.split(fname_new)[1][:-4] + 'match_masks.npz'), Cn=Cn,\n",
437-
" tp_gt=tp_gt, tp_comp=tp_comp, fn_gt=fn_gt, fp_comp=fp_comp, performance_cons_off=performance_cons_off, idx_size_neuro_gt=idx_size_neuro, A_thr=A_thr,\n",
438-
" A_gt=A, C_gt=C, b_gt=b, f_gt=f, YrA_gt=YrA, d1=d1, d2=d2, idx_components_gt=idx_size_neuro[\n",
439-
" tp_comp],\n",
440-
" idx_components_bad_gt=idx_size_neuro[fp_comp], fname_new=fname_new)\n"
489+
"plt.rc('font', **font)"
490+
]
491+
},
492+
{
493+
"cell_type": "markdown",
494+
"metadata": {},
495+
"source": [
496+
"### Generating match_masks.npz"
441497
]
442498
},
443499
{
444500
"cell_type": "code",
445501
"execution_count": null,
446502
"metadata": {},
447503
"outputs": [],
448-
"source": []
504+
"source": [
505+
"np.savez(os.path.join(os.path.split(fname_new)[0], os.path.split(fname_new)[1][:-4] + 'match_masks.npz'), Cn=Cn,\n",
506+
" tp_gt=tp_gt, tp_comp=tp_comp, fn_gt=fn_gt, fp_comp=fp_comp, performance_cons_off=performance_cons_off, idx_size_neuro_gt=idx_size_neuro, A_thr=A_thr,\n",
507+
" A_gt=A, C_gt=C, b_gt=b, f_gt=f, YrA_gt=YrA, d1=d1, d2=d2, idx_components_gt=idx_size_neuro[\n",
508+
" tp_comp],\n",
509+
" idx_components_bad_gt=idx_size_neuro[fp_comp], fname_new=fname_new)"
510+
]
449511
}
450512
],
451513
"metadata": {

0 commit comments

Comments
 (0)