From 774f75e35a564a8e3b1a36dfa05b562c87cdedf4 Mon Sep 17 00:00:00 2001 From: igardenia Date: Sun, 14 Jul 2019 19:06:23 +0800 Subject: [PATCH] Reduce the number of cycles --- demo/demo.ipynb | 38 ++++++++++++++------------------------ 1 file changed, 14 insertions(+), 24 deletions(-) diff --git a/demo/demo.ipynb b/demo/demo.ipynb index 2642b8460..2007c1241 100644 --- a/demo/demo.ipynb +++ b/demo/demo.ipynb @@ -48,7 +48,6 @@ "cell_type": "code", "execution_count": 2, "metadata": { - "collapsed": false, "scrolled": false }, "outputs": [ @@ -77,9 +76,7 @@ { "cell_type": "code", "execution_count": 3, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "data": { @@ -122,9 +119,7 @@ { "cell_type": "code", "execution_count": 4, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "data": { @@ -181,9 +176,7 @@ { "cell_type": "code", "execution_count": 6, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "data": { @@ -207,19 +200,16 @@ "\n", "detections = y.data\n", "# scale each detection back up to the image\n", - "scale = torch.Tensor(rgb_image.shape[1::-1]).repeat(2)\n", - "for i in range(detections.size(1)):\n", - " j = 0\n", - " while detections[0,i,j,0] >= 0.6:\n", - " score = detections[0,i,j,0]\n", - " label_name = labels[i-1]\n", - " display_txt = '%s: %.2f'%(label_name, score)\n", - " pt = (detections[0,i,j,1:]*scale).cpu().numpy()\n", - " coords = (pt[0], pt[1]), pt[2]-pt[0]+1, pt[3]-pt[1]+1\n", - " color = colors[i]\n", - " currentAxis.add_patch(plt.Rectangle(*coords, fill=False, edgecolor=color, linewidth=2))\n", - " currentAxis.text(pt[0], pt[1], display_txt, bbox={'facecolor':color, 'alpha':0.5})\n", - " j+=1" + "for _, (i, j) in enumerate(torch.nonzero(torch.gt(detections[0, :, :, 0], 0.6))):\n", + " score = detections[0,i,j,0]\n", + " label_name = labels[i-1]\n", + " display_txt = '%s: %.2f'%(label_name, score)\n", + " pt = (detections[0,i,j,1:]*scale).cpu().numpy()\n", + " coords = (pt[0], pt[1]), pt[2]-pt[0]+1, pt[3]-pt[1]+1\n", + " color = colors[i]\n", + " currentAxis.add_patch(plt.Rectangle(*coords, fill=False, edgecolor=color, linewidth=2))\n", + " currentAxis.text(pt[0], pt[1], display_txt, bbox={'facecolor':color, 'alpha':0.5})\n", + " j+=1" ] } ], @@ -240,7 +230,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.1" + "version": "3.7.3" } }, "nbformat": 4,