udacity / DSND_Term1

Contains files related to content and project of DSND

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Value Error in Notebook 'Part 7 - Loading Image Data (Exercises)' in intro-to-pytorch

AbhinavAK11 opened this issue · comments

This Error occurs while running the Solution given in Notebook

Error

Error

Error in callback <function install_repl_displayhook..post_execute at 0x7f60a397e6a8> (for post_execute):

ValueError Traceback (most recent call last)
/opt/conda/lib/python3.6/site-packages/matplotlib/pyplot.py in post_execute()
145 def post_execute():
146 if matplotlib.is_interactive():
--> 147 draw_all()
148
149 # IPython >= 2

/opt/conda/lib/python3.6/site-packages/matplotlib/_pylab_helpers.py in draw_all(cls, force)
148 for f_mgr in cls.get_all_fig_managers():
149 if force or f_mgr.canvas.figure.stale:
--> 150 f_mgr.canvas.draw_idle()
151
152 atexit.register(Gcf.destroy_all)

/opt/conda/lib/python3.6/site-packages/matplotlib/backend_bases.py in draw_idle(self, *args, **kwargs)
2051 if not self._is_idle_drawing:
2052 with self._idle_draw_cntx():
-> 2053 self.draw(*args, **kwargs)
2054
2055 def draw_cursor(self, event):

/opt/conda/lib/python3.6/site-packages/matplotlib/backends/backend_agg.py in draw(self)
428 if toolbar:
429 toolbar.set_cursor(cursors.WAIT)
--> 430 self.figure.draw(self.renderer)
431 finally:
432 if toolbar:

/opt/conda/lib/python3.6/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
53 renderer.start_filter()
54
---> 55 return draw(artist, renderer, *args, **kwargs)
56 finally:
57 if artist.get_agg_filter() is not None:

/opt/conda/lib/python3.6/site-packages/matplotlib/figure.py in draw(self, renderer)
1293
1294 mimage._draw_list_compositing_images(
-> 1295 renderer, self, artists, self.suppressComposite)
1296
1297 renderer.close_group('figure')

/opt/conda/lib/python3.6/site-packages/matplotlib/image.py in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
136 if not_composite or not has_images:
137 for a in artists:
--> 138 a.draw(renderer)
139 else:
140 # Composite any adjacent images together

/opt/conda/lib/python3.6/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
53 renderer.start_filter()
54
---> 55 return draw(artist, renderer, *args, **kwargs)
56 finally:
57 if artist.get_agg_filter() is not None:

/opt/conda/lib/python3.6/site-packages/matplotlib/axes/_base.py in draw(self, renderer, inframe)
2397 renderer.stop_rasterizing()
2398
-> 2399 mimage._draw_list_compositing_images(renderer, self, artists)
2400
2401 renderer.close_group('axes')

/opt/conda/lib/python3.6/site-packages/matplotlib/image.py in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
136 if not_composite or not has_images:
137 for a in artists:
--> 138 a.draw(renderer)
139 else:
140 # Composite any adjacent images together

/opt/conda/lib/python3.6/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
53 renderer.start_filter()
54
---> 55 return draw(artist, renderer, *args, **kwargs)
56 finally:
57 if artist.get_agg_filter() is not None:

/opt/conda/lib/python3.6/site-packages/matplotlib/image.py in draw(self, renderer, *args, **kwargs)
546 else:
547 im, l, b, trans = self.make_image(
--> 548 renderer, renderer.get_image_magnification())
549 if im is not None:
550 renderer.draw_image(gc, l, b, im)

/opt/conda/lib/python3.6/site-packages/matplotlib/image.py in make_image(self, renderer, magnification, unsampled)
772 return self._make_image(
773 self._A, bbox, transformed_bbox, self.axes.bbox, magnification,
--> 774 unsampled=unsampled)
775
776 def _check_unsampled_image(self, renderer):

/opt/conda/lib/python3.6/site-packages/matplotlib/image.py in _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification, unsampled, round_to_pixel_border)
464 # (of int or float)
465 # or an RGBA array of re-sampled input
--> 466 output = self.to_rgba(output, bytes=True, norm=False)
467 # output is now a correctly sized RGBA array of uint8
468

/opt/conda/lib/python3.6/site-packages/matplotlib/cm.py in to_rgba(self, x, alpha, bytes, norm)
255 if xx.dtype.kind == 'f':
256 if norm and xx.max() > 1 or xx.min() < 0:
--> 257 raise ValueError("Floating point image RGB values "
258 "must be in the 0..1 range.")
259 if bytes:

ValueError: Floating point image RGB values must be in the 0..1 range.


ValueError Traceback (most recent call last)
/opt/conda/lib/python3.6/site-packages/IPython/core/formatters.py in call(self, obj)
339 pass
340 else:
--> 341 return printer(obj)
342 # Finally look for special method names
343 method = get_real_method(obj, self.print_method)

/opt/conda/lib/python3.6/site-packages/IPython/core/pylabtools.py in (fig)
241 png_formatter.for_type(Figure, lambda fig: print_figure(fig, 'png', **kwargs))
242 if 'retina' in formats or 'png2x' in formats:
--> 243 png_formatter.for_type(Figure, lambda fig: retina_figure(fig, **kwargs))
244 if 'jpg' in formats or 'jpeg' in formats:
245 jpg_formatter.for_type(Figure, lambda fig: print_figure(fig, 'jpg', **kwargs))

/opt/conda/lib/python3.6/site-packages/IPython/core/pylabtools.py in retina_figure(fig, **kwargs)
131 def retina_figure(fig, **kwargs):
132 """format a figure as a pixel-doubled (retina) PNG"""
--> 133 pngdata = print_figure(fig, fmt='retina', **kwargs)
134 # Make sure that retina_figure acts just like print_figure and returns
135 # None when the figure is empty.

/opt/conda/lib/python3.6/site-packages/IPython/core/pylabtools.py in print_figure(fig, fmt, bbox_inches, **kwargs)
123
124 bytes_io = BytesIO()
--> 125 fig.canvas.print_figure(bytes_io, **kw)
126 data = bytes_io.getvalue()
127 if fmt == 'svg':

/opt/conda/lib/python3.6/site-packages/matplotlib/backend_bases.py in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, **kwargs)
2206 orientation=orientation,
2207 dryrun=True,
-> 2208 **kwargs)
2209 renderer = self.figure._cachedRenderer
2210 bbox_inches = self.figure.get_tightbbox(renderer)

/opt/conda/lib/python3.6/site-packages/matplotlib/backends/backend_agg.py in print_png(self, filename_or_obj, *args, **kwargs)
505
506 def print_png(self, filename_or_obj, *args, **kwargs):
--> 507 FigureCanvasAgg.draw(self)
508 renderer = self.get_renderer()
509 original_dpi = renderer.dpi

/opt/conda/lib/python3.6/site-packages/matplotlib/backends/backend_agg.py in draw(self)
428 if toolbar:
429 toolbar.set_cursor(cursors.WAIT)
--> 430 self.figure.draw(self.renderer)
431 finally:
432 if toolbar:

/opt/conda/lib/python3.6/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
53 renderer.start_filter()
54
---> 55 return draw(artist, renderer, *args, **kwargs)
56 finally:
57 if artist.get_agg_filter() is not None:

/opt/conda/lib/python3.6/site-packages/matplotlib/figure.py in draw(self, renderer)
1293
1294 mimage._draw_list_compositing_images(
-> 1295 renderer, self, artists, self.suppressComposite)
1296
1297 renderer.close_group('figure')

/opt/conda/lib/python3.6/site-packages/matplotlib/image.py in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
136 if not_composite or not has_images:
137 for a in artists:
--> 138 a.draw(renderer)
139 else:
140 # Composite any adjacent images together

/opt/conda/lib/python3.6/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
53 renderer.start_filter()
54
---> 55 return draw(artist, renderer, *args, **kwargs)
56 finally:
57 if artist.get_agg_filter() is not None:

/opt/conda/lib/python3.6/site-packages/matplotlib/axes/_base.py in draw(self, renderer, inframe)
2397 renderer.stop_rasterizing()
2398
-> 2399 mimage._draw_list_compositing_images(renderer, self, artists)
2400
2401 renderer.close_group('axes')

/opt/conda/lib/python3.6/site-packages/matplotlib/image.py in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
136 if not_composite or not has_images:
137 for a in artists:
--> 138 a.draw(renderer)
139 else:
140 # Composite any adjacent images together

/opt/conda/lib/python3.6/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
53 renderer.start_filter()
54
---> 55 return draw(artist, renderer, *args, **kwargs)
56 finally:
57 if artist.get_agg_filter() is not None:

/opt/conda/lib/python3.6/site-packages/matplotlib/image.py in draw(self, renderer, *args, **kwargs)
546 else:
547 im, l, b, trans = self.make_image(
--> 548 renderer, renderer.get_image_magnification())
549 if im is not None:
550 renderer.draw_image(gc, l, b, im)

/opt/conda/lib/python3.6/site-packages/matplotlib/image.py in make_image(self, renderer, magnification, unsampled)
772 return self._make_image(
773 self._A, bbox, transformed_bbox, self.axes.bbox, magnification,
--> 774 unsampled=unsampled)
775
776 def _check_unsampled_image(self, renderer):

/opt/conda/lib/python3.6/site-packages/matplotlib/image.py in _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification, unsampled, round_to_pixel_border)
464 # (of int or float)
465 # or an RGBA array of re-sampled input
--> 466 output = self.to_rgba(output, bytes=True, norm=False)
467 # output is now a correctly sized RGBA array of uint8
468

/opt/conda/lib/python3.6/site-packages/matplotlib/cm.py in to_rgba(self, x, alpha, bytes, norm)
255 if xx.dtype.kind == 'f':
256 if norm and xx.max() > 1 or xx.min() < 0:
--> 257 raise ValueError("Floating point image RGB values "
258 "must be in the 0..1 range.")
259 if bytes:

ValueError: Floating point image RGB values must be in the 0..1 range.

<matplotlib.figure.Figure at 0x7f607466c780>

Possible Solution

Changing the value of normalize as True, i.e.

helper.imshow(images[ii], ax=ax, normalize=True)

ErrorSolution

Thanks for reporting. We are triaging the issue.

Hi @AbhinavAK11

We did not face any bugs/errors while running the current code. We tested it both in the classroom workspace as well as the local Jupyter notebook server.

Though we would like to add a few points if you are running the notebook locally:

  1. The helper package used in the notebook is a custom script, helper.py, residing in the current working directory. So, make sure you have it too at the same relative path locally.

  2. You would have to download the Cat_Dog_data folder that contains the train/test images from the classroom workspace and place it at the same relative path locally.