PIL.UnidentifiedImageError: cannot identify image file <_io.BytesIO

The solution is two things:

  1. I had checked my “train” datasets very carefully, but I had not checked my “val” datasets for hidden files.

  2. When I did I found that there was a file named “.DS_Store”, which Mac OS X generates as a hidden file in every local folder (my database was originally created on a Mac). I also found that there were hidden copies of every file in each folder, including a "..DS_Store". This may have been caused by transferring the database to a Linux machine via a USB drive. These were not what was causing the error, .DS_Store and ..DS_Store were, but a whole database of duplicates is a serious waste of space.
    $ sudo rm ._* gets rid of the hidden files
    and sudo rm .D* gets rid of .DS_Store.

If you originate material on Mac and experience the PIL.UnidentifiedImageError you should check for hidden files before anything else.