Skip to content

Commit 065f5d5

Browse files
committed
Pushing the docs to dev/ for branch: main, commit 86301acc28bb70f0e18f4be0e0b2d1e694e897ef
1 parent 16a6755 commit 065f5d5

File tree

1,255 files changed

+4474
-4474
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,255 files changed

+4474
-4474
lines changed
Binary file not shown.

dev/_downloads/5bb71b0b2052531cacf3736b4d2b3a92/plot_face_compress.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
# %%
3737
# Thus the image is a 2D array of 768 pixels in height and 1024 pixels in width. Each
3838
# value is a 8-bit unsigned integer, which means that the image is encoded using 8
39-
# bits per pixel. The total memory usage of the image is 786 kilobytes (1 bytes equals
39+
# bits per pixel. The total memory usage of the image is 786 kilobytes (1 byte equals
4040
# 8 bits).
4141
#
4242
# Using 8-bit unsigned integer means that the image is encoded using 256 different
@@ -60,9 +60,9 @@
6060
#
6161
# The idea behind compression via vector quantization is to reduce the number of
6262
# gray levels to represent an image. For instance, we can use 8 values instead
63-
# of 256 values. Therefore, it means that we could efficiently use 1 bit instead
63+
# of 256 values. Therefore, it means that we could efficiently use 3 bits instead
6464
# of 8 bits to encode a single pixel and therefore reduce the memory usage by a
65-
# factor of 8. We will later discuss about this memory usage.
65+
# factor of approximately 2.5. We will later discuss about this memory usage.
6666
#
6767
# Encoding strategy
6868
# """""""""""""""""
@@ -91,7 +91,7 @@
9191
ax[1].set_xlabel("Pixel value")
9292
ax[1].set_ylabel("Count of pixels")
9393
ax[1].set_title("Sub-sampled distribution of the pixel values")
94-
_ = fig.suptitle("Raccoon face compressed using 1-bit and a uniform strategy")
94+
_ = fig.suptitle("Raccoon face compressed using 3 bits and a uniform strategy")
9595

9696
# %%
9797
# Qualitatively, we can spot some small regions where we see the effect of the
@@ -136,7 +136,7 @@
136136
ax[1].set_xlabel("Pixel value")
137137
ax[1].set_ylabel("Number of pixels")
138138
ax[1].set_title("Distribution of the pixel values")
139-
_ = fig.suptitle("Raccoon face compressed using 1-bit and a K-means strategy")
139+
_ = fig.suptitle("Raccoon face compressed using 3 bits and a K-means strategy")
140140

141141
# %%
142142
bin_edges = encoder.bin_edges_[0]
@@ -176,8 +176,8 @@
176176
# Indeed, the output of the :class:`~sklearn.preprocessing.KBinsDiscretizer` is
177177
# an array of 64-bit float. It means that it takes x8 more memory. However, we
178178
# use this 64-bit float representation to encode 8 values. Indeed, we will save
179-
# memory only if we cast the compressed image into an array of 1-bit integer. We
180-
# could use the method `numpy.ndarray.astype`. However, a 1-bit integer
179+
# memory only if we cast the compressed image into an array of 3-bits integers. We
180+
# could use the method `numpy.ndarray.astype`. However, a 3-bits integer
181181
# representation does not exist and to encode the 8 values, we would need to use
182182
# the 8-bit unsigned integer representation as well.
183183
#
Binary file not shown.

dev/_downloads/f52666c44d104a3e37802015751177fe/plot_face_compress.ipynb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
"cell_type": "markdown",
5252
"metadata": {},
5353
"source": [
54-
"Thus the image is a 2D array of 768 pixels in height and 1024 pixels in width. Each\nvalue is a 8-bit unsigned integer, which means that the image is encoded using 8\nbits per pixel. The total memory usage of the image is 786 kilobytes (1 bytes equals\n8 bits).\n\nUsing 8-bit unsigned integer means that the image is encoded using 256 different\nshades of gray, at most. We can check the distribution of these values.\n\n"
54+
"Thus the image is a 2D array of 768 pixels in height and 1024 pixels in width. Each\nvalue is a 8-bit unsigned integer, which means that the image is encoded using 8\nbits per pixel. The total memory usage of the image is 786 kilobytes (1 byte equals\n8 bits).\n\nUsing 8-bit unsigned integer means that the image is encoded using 256 different\nshades of gray, at most. We can check the distribution of these values.\n\n"
5555
]
5656
},
5757
{
@@ -69,7 +69,7 @@
6969
"cell_type": "markdown",
7070
"metadata": {},
7171
"source": [
72-
"## Compression via vector quantization\n\nThe idea behind compression via vector quantization is to reduce the number of\ngray levels to represent an image. For instance, we can use 8 values instead\nof 256 values. Therefore, it means that we could efficiently use 1 bit instead\nof 8 bits to encode a single pixel and therefore reduce the memory usage by a\nfactor of 8. We will later discuss about this memory usage.\n\n### Encoding strategy\n\nThe compression can be done using a\n:class:`~sklearn.preprocessing.KBinsDiscretizer`. We need to choose a strategy\nto define the 8 gray values to sub-sample. The simplest strategy is to define\nthem equally spaced, which correspond to setting `strategy=\"uniform\"`. From\nthe previous histogram, we know that this strategy is certainly not optimal.\n\n"
72+
"## Compression via vector quantization\n\nThe idea behind compression via vector quantization is to reduce the number of\ngray levels to represent an image. For instance, we can use 8 values instead\nof 256 values. Therefore, it means that we could efficiently use 3 bits instead\nof 8 bits to encode a single pixel and therefore reduce the memory usage by a\nfactor of approximately 2.5. We will later discuss about this memory usage.\n\n### Encoding strategy\n\nThe compression can be done using a\n:class:`~sklearn.preprocessing.KBinsDiscretizer`. We need to choose a strategy\nto define the 8 gray values to sub-sample. The simplest strategy is to define\nthem equally spaced, which correspond to setting `strategy=\"uniform\"`. From\nthe previous histogram, we know that this strategy is certainly not optimal.\n\n"
7373
]
7474
},
7575
{
@@ -80,7 +80,7 @@
8080
},
8181
"outputs": [],
8282
"source": [
83-
"from sklearn.preprocessing import KBinsDiscretizer\n\nn_bins = 8\nencoder = KBinsDiscretizer(\n n_bins=n_bins, encode=\"ordinal\", strategy=\"uniform\", random_state=0\n)\ncompressed_raccoon_uniform = encoder.fit_transform(raccoon_face.reshape(-1, 1)).reshape(\n raccoon_face.shape\n)\n\nfig, ax = plt.subplots(ncols=2, figsize=(12, 4))\nax[0].imshow(compressed_raccoon_uniform, cmap=plt.cm.gray)\nax[0].axis(\"off\")\nax[0].set_title(\"Rendering of the image\")\nax[1].hist(compressed_raccoon_uniform.ravel(), bins=256)\nax[1].set_xlabel(\"Pixel value\")\nax[1].set_ylabel(\"Count of pixels\")\nax[1].set_title(\"Sub-sampled distribution of the pixel values\")\n_ = fig.suptitle(\"Raccoon face compressed using 1-bit and a uniform strategy\")"
83+
"from sklearn.preprocessing import KBinsDiscretizer\n\nn_bins = 8\nencoder = KBinsDiscretizer(\n n_bins=n_bins, encode=\"ordinal\", strategy=\"uniform\", random_state=0\n)\ncompressed_raccoon_uniform = encoder.fit_transform(raccoon_face.reshape(-1, 1)).reshape(\n raccoon_face.shape\n)\n\nfig, ax = plt.subplots(ncols=2, figsize=(12, 4))\nax[0].imshow(compressed_raccoon_uniform, cmap=plt.cm.gray)\nax[0].axis(\"off\")\nax[0].set_title(\"Rendering of the image\")\nax[1].hist(compressed_raccoon_uniform.ravel(), bins=256)\nax[1].set_xlabel(\"Pixel value\")\nax[1].set_ylabel(\"Count of pixels\")\nax[1].set_title(\"Sub-sampled distribution of the pixel values\")\n_ = fig.suptitle(\"Raccoon face compressed using 3 bits and a uniform strategy\")"
8484
]
8585
},
8686
{
@@ -127,7 +127,7 @@
127127
},
128128
"outputs": [],
129129
"source": [
130-
"encoder = KBinsDiscretizer(\n n_bins=n_bins, encode=\"ordinal\", strategy=\"kmeans\", random_state=0\n)\ncompressed_raccoon_kmeans = encoder.fit_transform(raccoon_face.reshape(-1, 1)).reshape(\n raccoon_face.shape\n)\n\nfig, ax = plt.subplots(ncols=2, figsize=(12, 4))\nax[0].imshow(compressed_raccoon_kmeans, cmap=plt.cm.gray)\nax[0].axis(\"off\")\nax[0].set_title(\"Rendering of the image\")\nax[1].hist(compressed_raccoon_kmeans.ravel(), bins=256)\nax[1].set_xlabel(\"Pixel value\")\nax[1].set_ylabel(\"Number of pixels\")\nax[1].set_title(\"Distribution of the pixel values\")\n_ = fig.suptitle(\"Raccoon face compressed using 1-bit and a K-means strategy\")"
130+
"encoder = KBinsDiscretizer(\n n_bins=n_bins, encode=\"ordinal\", strategy=\"kmeans\", random_state=0\n)\ncompressed_raccoon_kmeans = encoder.fit_transform(raccoon_face.reshape(-1, 1)).reshape(\n raccoon_face.shape\n)\n\nfig, ax = plt.subplots(ncols=2, figsize=(12, 4))\nax[0].imshow(compressed_raccoon_kmeans, cmap=plt.cm.gray)\nax[0].axis(\"off\")\nax[0].set_title(\"Rendering of the image\")\nax[1].hist(compressed_raccoon_kmeans.ravel(), bins=256)\nax[1].set_xlabel(\"Pixel value\")\nax[1].set_ylabel(\"Number of pixels\")\nax[1].set_title(\"Distribution of the pixel values\")\n_ = fig.suptitle(\"Raccoon face compressed using 3 bits and a K-means strategy\")"
131131
]
132132
},
133133
{
@@ -192,7 +192,7 @@
192192
"cell_type": "markdown",
193193
"metadata": {},
194194
"source": [
195-
"Indeed, the output of the :class:`~sklearn.preprocessing.KBinsDiscretizer` is\nan array of 64-bit float. It means that it takes x8 more memory. However, we\nuse this 64-bit float representation to encode 8 values. Indeed, we will save\nmemory only if we cast the compressed image into an array of 1-bit integer. We\ncould use the method `numpy.ndarray.astype`. However, a 1-bit integer\nrepresentation does not exist and to encode the 8 values, we would need to use\nthe 8-bit unsigned integer representation as well.\n\nIn practice, observing a memory gain would require the original image to be in\na 64-bit float representation.\n\n"
195+
"Indeed, the output of the :class:`~sklearn.preprocessing.KBinsDiscretizer` is\nan array of 64-bit float. It means that it takes x8 more memory. However, we\nuse this 64-bit float representation to encode 8 values. Indeed, we will save\nmemory only if we cast the compressed image into an array of 3-bits integers. We\ncould use the method `numpy.ndarray.astype`. However, a 3-bits integer\nrepresentation does not exist and to encode the 8 values, we would need to use\nthe 8-bit unsigned integer representation as well.\n\nIn practice, observing a memory gain would require the original image to be in\na 64-bit float representation.\n\n"
196196
]
197197
}
198198
],

dev/_downloads/scikit-learn-docs.zip

1.07 KB
Binary file not shown.
-46 Bytes
179 Bytes
-18 Bytes
209 Bytes
9 Bytes

0 commit comments

Comments
 (0)