{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## Please install the itkwidgts before experiment\n", "details to install it can be found [here](https://github.com/InsightSoftwareConsortium/itkwidgets#installation)" ] }, { "cell_type": "code", "execution_count": 28, "metadata": { "scrolled": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Requirement already satisfied: scipy in /ssd2/tangshiyu/anaconda3/lib/python3.8/site-packages (1.6.2)\r\n", "Requirement already satisfied: numpy<1.23.0,>=1.16.5 in /ssd2/tangshiyu/anaconda3/lib/python3.8/site-packages (from scipy) (1.20.1)\r\n" ] } ], "source": [ "# Install dependencies for this example\n", "# Note: This does not include itkwidgets, itself\n", "import sys\n", "!{sys.executable} -m pip install scipy\n", "!wget https://bj.bcebos.com/paddleseg/paddleseg3d/lung_coronavirus/vnet_lung_coronavirus_128_128_128_15k_1e-3/prediction.npz" ] }, { "cell_type": "code", "execution_count": 29, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "from itkwidgets import view, compare\n", "\n", "# load the compressed data img=a, label=b, pred=c, infer=d\n", "data = np.load(\"prediction.npz\")\n", "\n", "# the infer output \n", "infer_result = data['infer'].squeeze()\n", "print(infer_result.shape)\n", "infer_result = infer_result*100\n", "\n", "# Ascent has a range of values from 0 to 255, but it is stored with a int64 dtype\n", "infer_result = infer_result.astype(np.uint8)\n", "\n", "b = data['pred'].squeeze()\n", "print(b.shape)\n", "b = b*100\n", "\n", "# Ascent has a range of values from 0 to 255, but it is stored with a int64 dtype\n", "b = b.astype(np.uint8)\n", "\n", "c = data['label'].squeeze()\n", "print(b.shape)\n", "c = c*100\n", "\n", "# Ascent has a range of values from 0 to 255, but it is stored with a int64 dtype\n", "c = c.astype(np.uint8)\n", "\n", "d = data['img'].squeeze()\n", "print(d.shape)\n", "d = d*100\n", "\n", "# Ascent has a range of values from 0 to 255, but it is stored with a int64 dtype\n", "d = d.astype(np.uint8)\n", "\n", "# b is pred, c is label, d is img\n", "predlabel = np.concatenate((b, c), axis=1)" ] }, { "cell_type": "code", "execution_count": 35, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "(128, 256, 128)\n" ] }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "762485dcc73340b0a2b23c6eee6eaf3f", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Viewer(axes=True, geometries=[], gradient_opacity=1.0, point_sets=[], rendered_image=\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 13\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 14\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 15\u001b[0;31m \u001b[0mpredlabel\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mconcatenate\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmri_pred\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmri_label\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0maxis\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m2\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 16\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 17\u001b[0m \u001b[0mpredlabel\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mshape\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;32m<__array_function__ internals>\u001b[0m in \u001b[0;36mconcatenate\u001b[0;34m(*args, **kwargs)\u001b[0m\n", "\u001b[0;31mValueError\u001b[0m: all the input arrays must have same number of dimensions, but the array at index 0 has 3 dimension(s) and the array at index 1 has 4 dimension(s)" ] } ], "source": [ "# visualize MRI\n", "import numpy as np\n", "from itkwidgets import view, compare\n", "\n", "mri_img = np.load(\"saved_model/vnet_mri_spine_seg_128_128_24_15k_0309_rmmax/1_img.npy\")\n", "mri_label = np.load(\"saved_model/vnet_mri_spine_seg_128_128_24_15k_0309_rmmax/1_label.npy\") * 10\n", "mri_pred = np.load(\" saved_model/vnet_mri_spine_seg_128_128_24_15k_0309_rmmax/1_pred.npy\") * 10\n", "\n", "# Ascent has a range of values from 0 to 255, but it is stored with a int64 dtype\n", "mri_img = mri_img.astype(np.uint8)\n", "mri_label = mri_label.astype(np.uint8)\n", "mri_pred = mri_pred.astype(np.uint8)\n", "\n", "\n", "predlabel = np.concatenate((mri_pred, mri_label), axis=2)\n", "\n", "predlabel.shape" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "6cf8328d4cdd4f4293c10ea116d261be", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Viewer(geometries=[], gradient_opacity=1.0, point_sets=[], rendered_image=