1616"""Cats vs Dogs dataset."""
1717
1818import io
19+ import os
1920import re
2021import zipfile
2122
4344_NUM_CORRUPT_IMAGES = 1738
4445_DESCRIPTION = (
4546 "A large set of images of cats and dogs. "
46- "There are %d corrupted images that are dropped." % _NUM_CORRUPT_IMAGES
47+ f "There are { _NUM_CORRUPT_IMAGES } corrupted images that are dropped."
4748)
4849
4950_NAME_RE = re .compile (r"^PetImages[\\/](Cat|Dog)[\\/]\d+\.jpg$" )
@@ -94,7 +95,8 @@ def _generate_examples(self, archive):
9495 """Generate Cats vs Dogs images and labels given a directory path."""
9596 num_skipped = 0
9697 for fname , fobj in archive :
97- res = _NAME_RE .match (fname )
98+ norm_fname = os .path .normpath (fname )
99+ res = _NAME_RE .match (norm_fname )
98100 if not res : # README file, ...
99101 continue
100102 label = res .group (1 ).lower ()
@@ -113,19 +115,19 @@ def _generate_examples(self, archive):
113115 # Converting the recoded image back into a zip file container.
114116 buffer = io .BytesIO ()
115117 with zipfile .ZipFile (buffer , "w" ) as new_zip :
116- new_zip .writestr (fname , img_recoded .numpy ())
117- new_fobj = zipfile .ZipFile (buffer ).open (fname )
118+ new_zip .writestr (norm_fname , img_recoded .numpy ())
119+ new_fobj = zipfile .ZipFile (buffer ).open (norm_fname )
118120
119121 record = {
120122 "image" : new_fobj ,
121- "image/filename" : fname ,
123+ "image/filename" : norm_fname ,
122124 "label" : label ,
123125 }
124- yield fname , record
126+ yield norm_fname , record
125127
126128 if num_skipped != _NUM_CORRUPT_IMAGES :
127129 raise ValueError (
128- "Expected %d corrupt images, but found %d "
129- % ( _NUM_CORRUPT_IMAGES , num_skipped )
130+ f "Expected { _NUM_CORRUPT_IMAGES } corrupt images, but found"
131+ f" { num_skipped } ."
130132 )
131133 logging .warning ("%d images were corrupted and were skipped" , num_skipped )
0 commit comments