|
22 | 22 | "import numpy as np\n", |
23 | 23 | "import matplotlib.pyplot as plt\n", |
24 | 24 | "%matplotlib inline\n", |
25 | | - "import Image\n", |
26 | 25 | "\n", |
27 | 26 | "# Make sure that caffe is on the python path:\n", |
28 | 27 | "caffe_root = '../' # this file is expected to be in {caffe_root}/examples\n", |
|
3511 | 3510 | "print(\"blobs {}\\nparams {}\".format(net.blobs.keys(), net.params.keys()))\n", |
3512 | 3511 | "\n", |
3513 | 3512 | "# 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", |
3515 | 3514 | "plt.title(\"original image\")\n", |
3516 | 3515 | "plt.imshow(im)\n", |
3517 | 3516 | "plt.axis('off')\n", |
|
4480 | 4479 | "name": "stdout", |
4481 | 4480 | "output_type": "stream", |
4482 | 4481 | "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" |
4485 | 4484 | ] |
4486 | 4485 | } |
4487 | 4486 | ], |
4488 | 4487 | "source": [ |
4489 | 4488 | "# pick first filter output\n", |
4490 | 4489 | "conv0 = net.blobs['conv'].data[0, 0]\n", |
4491 | 4490 | "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", |
4493 | 4492 | "net.params['conv'][1].data[0] = 1.\n", |
4494 | 4493 | "net.forward()\n", |
4495 | 4494 | "print(\"post-surgery output mean {:.2f}\".format(conv0.mean()))" |
|
5494 | 5493 | "name": "stdout", |
5495 | 5494 | "output_type": "stream", |
5496 | 5495 | "text": [ |
5497 | | - "1,2c1,2\r\n", |
| 5496 | + "1,2c1\r\n", |
5498 | 5497 | "< # Fully convolutional network version of CaffeNet.\r\n", |
5499 | 5498 | "< name: \"CaffeNetConv\"\r\n", |
5500 | 5499 | "---\r\n", |
5501 | 5500 | "> name: \"CaffeNet\"\r\n", |
5502 | | - "> input: \"data\"\r\n", |
5503 | | - "7,11c7\r\n", |
| 5501 | + "7,11c6\r\n", |
5504 | 5502 | "< input_param {\r\n", |
5505 | 5503 | "< # initial shape for a fully convolutional network:\r\n", |
5506 | 5504 | "< # the shape can be set for each input by reshape.\r\n", |
5507 | 5505 | "< shape: { dim: 1 dim: 3 dim: 451 dim: 451 }\r\n", |
5508 | 5506 | "< }\r\n", |
5509 | 5507 | "---\r\n", |
5510 | 5508 | "> 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", |
5512 | 5510 | "< name: \"fc6-conv\"\r\n", |
5513 | 5511 | "< type: \"Convolution\"\r\n", |
5514 | 5512 | "---\r\n", |
5515 | 5513 | "> name: \"fc6\"\r\n", |
5516 | 5514 | "> type: \"InnerProduct\"\r\n", |
5517 | | - "160,161c156,157\r\n", |
| 5515 | + "160,161c155,156\r\n", |
5518 | 5516 | "< top: \"fc6-conv\"\r\n", |
5519 | 5517 | "< convolution_param {\r\n", |
5520 | 5518 | "---\r\n", |
5521 | 5519 | "> top: \"fc6\"\r\n", |
5522 | 5520 | "> inner_product_param {\r\n", |
5523 | | - "163d158\r\n", |
| 5521 | + "163d157\r\n", |
5524 | 5522 | "< kernel_size: 6\r\n", |
5525 | | - "169,170c164,165\r\n", |
| 5523 | + "169,170c163,164\r\n", |
5526 | 5524 | "< bottom: \"fc6-conv\"\r\n", |
5527 | 5525 | "< top: \"fc6-conv\"\r\n", |
5528 | 5526 | "---\r\n", |
5529 | 5527 | "> bottom: \"fc6\"\r\n", |
5530 | 5528 | "> top: \"fc6\"\r\n", |
5531 | | - "175,176c170,171\r\n", |
| 5529 | + "175,176c169,170\r\n", |
5532 | 5530 | "< bottom: \"fc6-conv\"\r\n", |
5533 | 5531 | "< top: \"fc6-conv\"\r\n", |
5534 | 5532 | "---\r\n", |
5535 | 5533 | "> bottom: \"fc6\"\r\n", |
5536 | 5534 | "> top: \"fc6\"\r\n", |
5537 | | - "182,186c177,181\r\n", |
| 5535 | + "182,186c176,180\r\n", |
5538 | 5536 | "< name: \"fc7-conv\"\r\n", |
5539 | 5537 | "< type: \"Convolution\"\r\n", |
5540 | 5538 | "< bottom: \"fc6-conv\"\r\n", |
|
5546 | 5544 | "> bottom: \"fc6\"\r\n", |
5547 | 5545 | "> top: \"fc7\"\r\n", |
5548 | 5546 | "> inner_product_param {\r\n", |
5549 | | - "188d182\r\n", |
| 5547 | + "188d181\r\n", |
5550 | 5548 | "< kernel_size: 1\r\n", |
5551 | | - "194,195c188,189\r\n", |
| 5549 | + "194,195c187,188\r\n", |
5552 | 5550 | "< bottom: \"fc7-conv\"\r\n", |
5553 | 5551 | "< top: \"fc7-conv\"\r\n", |
5554 | 5552 | "---\r\n", |
5555 | 5553 | "> bottom: \"fc7\"\r\n", |
5556 | 5554 | "> top: \"fc7\"\r\n", |
5557 | | - "200,201c194,195\r\n", |
| 5555 | + "200,201c193,194\r\n", |
5558 | 5556 | "< bottom: \"fc7-conv\"\r\n", |
5559 | 5557 | "< top: \"fc7-conv\"\r\n", |
5560 | 5558 | "---\r\n", |
5561 | 5559 | "> bottom: \"fc7\"\r\n", |
5562 | 5560 | "> top: \"fc7\"\r\n", |
5563 | | - "207,211c201,205\r\n", |
| 5561 | + "207,211c200,204\r\n", |
5564 | 5562 | "< name: \"fc8-conv\"\r\n", |
5565 | 5563 | "< type: \"Convolution\"\r\n", |
5566 | 5564 | "< bottom: \"fc7-conv\"\r\n", |
|
5572 | 5570 | "> bottom: \"fc7\"\r\n", |
5573 | 5571 | "> top: \"fc8\"\r\n", |
5574 | 5572 | "> inner_product_param {\r\n", |
5575 | | - "213d206\r\n", |
| 5573 | + "213d205\r\n", |
5576 | 5574 | "< kernel_size: 1\r\n", |
5577 | | - "219c212\r\n", |
| 5575 | + "219c211\r\n", |
5578 | 5576 | "< bottom: \"fc8-conv\"\r\n", |
5579 | 5577 | "---\r\n", |
5580 | 5578 | "> bottom: \"fc8\"\r\n" |
|
5610 | 5608 | } |
5611 | 5609 | ], |
5612 | 5610 | "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", |
5620 | 5611 | "# Load the original network and extract the fully connected layers' parameters.\n", |
5621 | 5612 | "net = caffe.Net('../models/bvlc_reference_caffenet/deploy.prototxt', \n", |
5622 | 5613 | " '../models/bvlc_reference_caffenet/bvlc_reference_caffenet.caffemodel', \n", |
|
0 commit comments