Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions examples/vision/ipynb/visualizing_what_convnets_learn.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@
"source": [
"def initialize_image():\n",
" # We start from a gray image with some random noise\n",
" img = tf.random.uniform((1, img_width, img_height, 3))\n",
" img = tf.random.uniform((1, img_height, img_width, 3))\n",
" # ResNet50V2 expects inputs in the range [-1, +1].\n",
" # Here we scale our random inputs to [-0.125, +0.125]\n",
" return (img - 0.5) * 0.25\n",
Expand Down Expand Up @@ -293,16 +293,16 @@
"cropped_height = img_height - 25 * 2\n",
"width = n * cropped_width + (n - 1) * margin\n",
"height = n * cropped_height + (n - 1) * margin\n",
"stitched_filters = np.zeros((width, height, 3))\n",
"stitched_filters = np.zeros((height, width, 3))\n",
"\n",
"# Fill the picture with our saved filters\n",
"for i in range(n):\n",
" for j in range(n):\n",
" img = all_imgs[i * n + j]\n",
" stitched_filters[\n",
" (cropped_width + margin) * i : (cropped_width + margin) * i + cropped_width,\n",
" (cropped_height + margin) * j : (cropped_height + margin) * j\n",
" + cropped_height,\n",
" (cropped_height + margin) * i : (cropped_height + margin) * i + cropped_height,\n",
" (cropped_width + margin) * j : (cropped_width + margin) * j\n",
" + cropped_width,\n",
Comment on lines +303 to +305
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

While this slicing logic is correct, it's a bit dense and can be hard to parse. For improved readability and maintainability, consider extracting the start and end coordinates into separate variables. This makes the logic clearer.

For example:

# Inside the loops
row_start = i * (cropped_height + margin)
row_end = row_start + cropped_height
col_start = j * (cropped_width + margin)
col_end = col_start + cropped_width
stitched_filters[row_start:row_end, col_start:col_end, :] = img

This change would make the code's intent more explicit.

" :,\n",
" ] = img\n",
"keras.utils.save_img(\"stiched_filters.png\", stitched_filters)\n",
Expand Down
10 changes: 5 additions & 5 deletions examples/vision/md/visualizing_what_convnets_learn.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ center-cropping it, and restricting it to the [0, 255] range.

def initialize_image():
# We start from a gray image with some random noise
img = tf.random.uniform((1, img_width, img_height, 3))
img = tf.random.uniform((1, img_height, img_width, 3))
# ResNet50V2 expects inputs in the range [-1, +1].
# Here we scale our random inputs to [-0.125, +0.125]
return (img - 0.5) * 0.25
Expand Down Expand Up @@ -196,16 +196,16 @@ cropped_width = img_width - 25 * 2
cropped_height = img_height - 25 * 2
width = n * cropped_width + (n - 1) * margin
height = n * cropped_height + (n - 1) * margin
stitched_filters = np.zeros((width, height, 3))
stitched_filters = np.zeros((height, width, 3))

# Fill the picture with our saved filters
for i in range(n):
for j in range(n):
img = all_imgs[i * n + j]
stitched_filters[
(cropped_width + margin) * i : (cropped_width + margin) * i + cropped_width,
(cropped_height + margin) * j : (cropped_height + margin) * j
+ cropped_height,
(cropped_height + margin) * i : (cropped_height + margin) * i + cropped_height,
(cropped_width + margin) * j : (cropped_width + margin) * j
+ cropped_width,
Comment on lines +206 to +208
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

While this slicing logic is correct, it's a bit dense and can be hard to parse. For improved readability and maintainability, consider extracting the start and end coordinates into separate variables. This makes the logic clearer.

For example:

# Inside the loops
row_start = i * (cropped_height + margin)
row_end = row_start + cropped_height
col_start = j * (cropped_width + margin)
col_end = col_start + cropped_width
stitched_filters[row_start:row_end, col_start:col_end, :] = img

This change would make the code's intent more explicit.

:,
] = img
keras.utils.save_img("stiched_filters.png", stitched_filters)
Expand Down
10 changes: 5 additions & 5 deletions examples/vision/visualizing_what_convnets_learn.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def gradient_ascent_step(img, filter_index, learning_rate):

def initialize_image():
# We start from a gray image with some random noise
img = tf.random.uniform((1, img_width, img_height, 3))
img = tf.random.uniform((1, img_height, img_width, 3))
# ResNet50V2 expects inputs in the range [-1, +1].
# Here we scale our random inputs to [-0.125, +0.125]
return (img - 0.5) * 0.25
Expand Down Expand Up @@ -176,16 +176,16 @@ def deprocess_image(img):
cropped_height = img_height - 25 * 2
width = n * cropped_width + (n - 1) * margin
height = n * cropped_height + (n - 1) * margin
stitched_filters = np.zeros((width, height, 3))
stitched_filters = np.zeros((height, width, 3))

# Fill the picture with our saved filters
for i in range(n):
for j in range(n):
img = all_imgs[i * n + j]
stitched_filters[
(cropped_width + margin) * i : (cropped_width + margin) * i + cropped_width,
(cropped_height + margin) * j : (cropped_height + margin) * j
+ cropped_height,
(cropped_height + margin) * i : (cropped_height + margin) * i + cropped_height,
(cropped_width + margin) * j : (cropped_width + margin) * j
+ cropped_width,
Comment on lines +186 to +188
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

While this slicing logic is correct, it's a bit dense and can be hard to parse. For improved readability and maintainability, consider extracting the start and end coordinates into separate variables. This makes the logic clearer.

For example:

# Inside the loops
row_start = i * (cropped_height + margin)
row_end = row_start + cropped_height
col_start = j * (cropped_width + margin)
col_end = col_start + cropped_width
stitched_filters[row_start:row_end, col_start:col_end, :] = img

This change would make the code's intent more explicit.

:,
] = img
keras.utils.save_img("stiched_filters.png", stitched_filters)
Expand Down
Loading