Skip to content

Commit 4e690b2

Browse files
committed
fix problems in net_surgery.ipynb
1 parent c6d93da commit 4e690b2

1 file changed

Lines changed: 18 additions & 27 deletions

File tree

examples/net_surgery.ipynb

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
"import numpy as np\n",
2323
"import matplotlib.pyplot as plt\n",
2424
"%matplotlib inline\n",
25-
"import Image\n",
2625
"\n",
2726
"# Make sure that caffe is on the python path:\n",
2827
"caffe_root = '../' # this file is expected to be in {caffe_root}/examples\n",
@@ -3511,7 +3510,7 @@
35113510
"print(\"blobs {}\\nparams {}\".format(net.blobs.keys(), net.params.keys()))\n",
35123511
"\n",
35133512
"# load image and prepare as a single input batch for Caffe\n",
3514-
"im = np.array(Image.open('images/cat_gray.jpg'))\n",
3513+
"im = np.array(caffe.io.load_image('images/cat_gray.jpg', color=False)).squeeze()\n",
35153514
"plt.title(\"original image\")\n",
35163515
"plt.imshow(im)\n",
35173516
"plt.axis('off')\n",
@@ -4480,16 +4479,16 @@
44804479
"name": "stdout",
44814480
"output_type": "stream",
44824481
"text": [
4483-
"pre-surgery output mean -12.93\n",
4484-
"post-surgery output mean -11.93\n"
4482+
"pre-surgery output mean -0.02\n",
4483+
"post-surgery output mean 0.98\n"
44854484
]
44864485
}
44874486
],
44884487
"source": [
44894488
"# pick first filter output\n",
44904489
"conv0 = net.blobs['conv'].data[0, 0]\n",
44914490
"print(\"pre-surgery output mean {:.2f}\".format(conv0.mean()))\n",
4492-
"# set first filter bias to 10\n",
4491+
"# set first filter bias to 1\n",
44934492
"net.params['conv'][1].data[0] = 1.\n",
44944493
"net.forward()\n",
44954494
"print(\"post-surgery output mean {:.2f}\".format(conv0.mean()))"
@@ -5494,47 +5493,46 @@
54945493
"name": "stdout",
54955494
"output_type": "stream",
54965495
"text": [
5497-
"1,2c1,2\r\n",
5496+
"1,2c1\r\n",
54985497
"< # Fully convolutional network version of CaffeNet.\r\n",
54995498
"< name: \"CaffeNetConv\"\r\n",
55005499
"---\r\n",
55015500
"> name: \"CaffeNet\"\r\n",
5502-
"> input: \"data\"\r\n",
5503-
"7,11c7\r\n",
5501+
"7,11c6\r\n",
55045502
"< input_param {\r\n",
55055503
"< # initial shape for a fully convolutional network:\r\n",
55065504
"< # the shape can be set for each input by reshape.\r\n",
55075505
"< shape: { dim: 1 dim: 3 dim: 451 dim: 451 }\r\n",
55085506
"< }\r\n",
55095507
"---\r\n",
55105508
"> input_param { shape: { dim: 10 dim: 3 dim: 227 dim: 227 } }\r\n",
5511-
"157,158c153,154\r\n",
5509+
"157,158c152,153\r\n",
55125510
"< name: \"fc6-conv\"\r\n",
55135511
"< type: \"Convolution\"\r\n",
55145512
"---\r\n",
55155513
"> name: \"fc6\"\r\n",
55165514
"> type: \"InnerProduct\"\r\n",
5517-
"160,161c156,157\r\n",
5515+
"160,161c155,156\r\n",
55185516
"< top: \"fc6-conv\"\r\n",
55195517
"< convolution_param {\r\n",
55205518
"---\r\n",
55215519
"> top: \"fc6\"\r\n",
55225520
"> inner_product_param {\r\n",
5523-
"163d158\r\n",
5521+
"163d157\r\n",
55245522
"< kernel_size: 6\r\n",
5525-
"169,170c164,165\r\n",
5523+
"169,170c163,164\r\n",
55265524
"< bottom: \"fc6-conv\"\r\n",
55275525
"< top: \"fc6-conv\"\r\n",
55285526
"---\r\n",
55295527
"> bottom: \"fc6\"\r\n",
55305528
"> top: \"fc6\"\r\n",
5531-
"175,176c170,171\r\n",
5529+
"175,176c169,170\r\n",
55325530
"< bottom: \"fc6-conv\"\r\n",
55335531
"< top: \"fc6-conv\"\r\n",
55345532
"---\r\n",
55355533
"> bottom: \"fc6\"\r\n",
55365534
"> top: \"fc6\"\r\n",
5537-
"182,186c177,181\r\n",
5535+
"182,186c176,180\r\n",
55385536
"< name: \"fc7-conv\"\r\n",
55395537
"< type: \"Convolution\"\r\n",
55405538
"< bottom: \"fc6-conv\"\r\n",
@@ -5546,21 +5544,21 @@
55465544
"> bottom: \"fc6\"\r\n",
55475545
"> top: \"fc7\"\r\n",
55485546
"> inner_product_param {\r\n",
5549-
"188d182\r\n",
5547+
"188d181\r\n",
55505548
"< kernel_size: 1\r\n",
5551-
"194,195c188,189\r\n",
5549+
"194,195c187,188\r\n",
55525550
"< bottom: \"fc7-conv\"\r\n",
55535551
"< top: \"fc7-conv\"\r\n",
55545552
"---\r\n",
55555553
"> bottom: \"fc7\"\r\n",
55565554
"> top: \"fc7\"\r\n",
5557-
"200,201c194,195\r\n",
5555+
"200,201c193,194\r\n",
55585556
"< bottom: \"fc7-conv\"\r\n",
55595557
"< top: \"fc7-conv\"\r\n",
55605558
"---\r\n",
55615559
"> bottom: \"fc7\"\r\n",
55625560
"> top: \"fc7\"\r\n",
5563-
"207,211c201,205\r\n",
5561+
"207,211c200,204\r\n",
55645562
"< name: \"fc8-conv\"\r\n",
55655563
"< type: \"Convolution\"\r\n",
55665564
"< bottom: \"fc7-conv\"\r\n",
@@ -5572,9 +5570,9 @@
55725570
"> bottom: \"fc7\"\r\n",
55735571
"> top: \"fc8\"\r\n",
55745572
"> inner_product_param {\r\n",
5575-
"213d206\r\n",
5573+
"213d205\r\n",
55765574
"< kernel_size: 1\r\n",
5577-
"219c212\r\n",
5575+
"219c211\r\n",
55785576
"< bottom: \"fc8-conv\"\r\n",
55795577
"---\r\n",
55805578
"> bottom: \"fc8\"\r\n"
@@ -5610,13 +5608,6 @@
56105608
}
56115609
],
56125610
"source": [
5613-
"# Make sure that caffe is on the python path:\n",
5614-
"caffe_root = '../' # this file is expected to be in {caffe_root}/examples\n",
5615-
"import sys\n",
5616-
"sys.path.insert(0, caffe_root + 'python')\n",
5617-
"\n",
5618-
"import caffe\n",
5619-
"\n",
56205611
"# Load the original network and extract the fully connected layers' parameters.\n",
56215612
"net = caffe.Net('../models/bvlc_reference_caffenet/deploy.prototxt', \n",
56225613
" '../models/bvlc_reference_caffenet/bvlc_reference_caffenet.caffemodel', \n",

0 commit comments

Comments
 (0)