Created using Colab
This commit is contained in:
@@ -4,7 +4,6 @@
|
|||||||
"metadata": {
|
"metadata": {
|
||||||
"colab": {
|
"colab": {
|
||||||
"provenance": [],
|
"provenance": [],
|
||||||
"authorship_tag": "ABX9TyMbSR8fzpXvO6TIQdO7bI0H",
|
|
||||||
"include_colab_link": true
|
"include_colab_link": true
|
||||||
},
|
},
|
||||||
"kernelspec": {
|
"kernelspec": {
|
||||||
@@ -71,9 +70,9 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"source": [
|
"source": [
|
||||||
"def subsample(x_in):\n",
|
"def downsample(x_in):\n",
|
||||||
" x_out = np.zeros(( int(np.ceil(x_in.shape[0]/2)), int(np.ceil(x_in.shape[1]/2)) ))\n",
|
" x_out = np.zeros(( int(np.ceil(x_in.shape[0]/2)), int(np.ceil(x_in.shape[1]/2)) ))\n",
|
||||||
" # TODO -- write the subsampling routine\n",
|
" # TODO -- write the downsampling routine\n",
|
||||||
" # Replace this line\n",
|
" # Replace this line\n",
|
||||||
" x_out = x_out\n",
|
" x_out = x_out\n",
|
||||||
"\n",
|
"\n",
|
||||||
@@ -91,8 +90,8 @@
|
|||||||
"source": [
|
"source": [
|
||||||
"print(\"Original:\")\n",
|
"print(\"Original:\")\n",
|
||||||
"print(orig_4_4)\n",
|
"print(orig_4_4)\n",
|
||||||
"print(\"Subsampled:\")\n",
|
"print(\"Downsampled:\")\n",
|
||||||
"print(subsample(orig_4_4))"
|
"print(downsample(orig_4_4))"
|
||||||
],
|
],
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"id": "O_i0y72_JwGZ"
|
"id": "O_i0y72_JwGZ"
|
||||||
@@ -127,24 +126,24 @@
|
|||||||
"image = Image.open('test_image.png')\n",
|
"image = Image.open('test_image.png')\n",
|
||||||
"# convert image to numpy array\n",
|
"# convert image to numpy array\n",
|
||||||
"data = asarray(image)\n",
|
"data = asarray(image)\n",
|
||||||
"data_subsample = subsample(data);\n",
|
"data_downsample = downsample(data);\n",
|
||||||
"\n",
|
"\n",
|
||||||
"plt.figure(figsize=(5,5))\n",
|
"plt.figure(figsize=(5,5))\n",
|
||||||
"plt.imshow(data, cmap='gray')\n",
|
"plt.imshow(data, cmap='gray')\n",
|
||||||
"plt.show()\n",
|
"plt.show()\n",
|
||||||
"\n",
|
"\n",
|
||||||
"plt.figure(figsize=(5,5))\n",
|
"plt.figure(figsize=(5,5))\n",
|
||||||
"plt.imshow(data_subsample, cmap='gray')\n",
|
"plt.imshow(data_downsample, cmap='gray')\n",
|
||||||
"plt.show()\n",
|
"plt.show()\n",
|
||||||
"\n",
|
"\n",
|
||||||
"data_subsample2 = subsample(data_subsample)\n",
|
"data_downsample2 = downsample(data_downsample)\n",
|
||||||
"plt.figure(figsize=(5,5))\n",
|
"plt.figure(figsize=(5,5))\n",
|
||||||
"plt.imshow(data_subsample2, cmap='gray')\n",
|
"plt.imshow(data_downsample2, cmap='gray')\n",
|
||||||
"plt.show()\n",
|
"plt.show()\n",
|
||||||
"\n",
|
"\n",
|
||||||
"data_subsample3 = subsample(data_subsample2)\n",
|
"data_downsample3 = downsample(data_downsample2)\n",
|
||||||
"plt.figure(figsize=(5,5))\n",
|
"plt.figure(figsize=(5,5))\n",
|
||||||
"plt.imshow(data_subsample3, cmap='gray')\n",
|
"plt.imshow(data_downsample3, cmap='gray')\n",
|
||||||
"plt.show()"
|
"plt.show()"
|
||||||
],
|
],
|
||||||
"metadata": {
|
"metadata": {
|
||||||
@@ -345,11 +344,11 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"source": [
|
"source": [
|
||||||
"# Let's re-upsample, sub-sampled rick\n",
|
"# Let's re-upsample, downsampled rick\n",
|
||||||
"data_duplicate = duplicate(data_subsample3);\n",
|
"data_duplicate = duplicate(data_downsample3);\n",
|
||||||
"\n",
|
"\n",
|
||||||
"plt.figure(figsize=(5,5))\n",
|
"plt.figure(figsize=(5,5))\n",
|
||||||
"plt.imshow(data_subsample3, cmap='gray')\n",
|
"plt.imshow(data_downsample3, cmap='gray')\n",
|
||||||
"plt.show()\n",
|
"plt.show()\n",
|
||||||
"\n",
|
"\n",
|
||||||
"plt.figure(figsize=(5,5))\n",
|
"plt.figure(figsize=(5,5))\n",
|
||||||
@@ -388,7 +387,7 @@
|
|||||||
"# The input x_high_res is the original high res image, from which you can deduce the position of the maximum index\n",
|
"# The input x_high_res is the original high res image, from which you can deduce the position of the maximum index\n",
|
||||||
"def max_unpool(x_in, x_high_res):\n",
|
"def max_unpool(x_in, x_high_res):\n",
|
||||||
" x_out = np.zeros(( x_in.shape[0]*2, x_in.shape[1]*2 ))\n",
|
" x_out = np.zeros(( x_in.shape[0]*2, x_in.shape[1]*2 ))\n",
|
||||||
" # TODO -- write the subsampling routine\n",
|
" # TODO -- write the unpooling routine\n",
|
||||||
" # Replace this line\n",
|
" # Replace this line\n",
|
||||||
" x_out = x_out\n",
|
" x_out = x_out\n",
|
||||||
"\n",
|
"\n",
|
||||||
@@ -417,7 +416,7 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"source": [
|
"source": [
|
||||||
"# Let's re-upsample, sub-sampled rick\n",
|
"# Let's re-upsample, down-sampled rick\n",
|
||||||
"data_max_unpool= max_unpool(data_maxpool3,data_maxpool2);\n",
|
"data_max_unpool= max_unpool(data_maxpool3,data_maxpool2);\n",
|
||||||
"\n",
|
"\n",
|
||||||
"plt.figure(figsize=(5,5))\n",
|
"plt.figure(figsize=(5,5))\n",
|
||||||
@@ -489,7 +488,7 @@
|
|||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"source": [
|
"source": [
|
||||||
"# Let's re-upsample, sub-sampled rick\n",
|
"# Let's re-upsample, down-sampled rick\n",
|
||||||
"data_bilinear = bilinear(data_meanpool3);\n",
|
"data_bilinear = bilinear(data_meanpool3);\n",
|
||||||
"\n",
|
"\n",
|
||||||
"plt.figure(figsize=(5,5))\n",
|
"plt.figure(figsize=(5,5))\n",
|
||||||
@@ -517,4 +516,4 @@
|
|||||||
"outputs": []
|
"outputs": []
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user