(path, src_dir, image_channel_size=3)
Args:
            path(str):
            src_dir(str):

        Yields:
            img: and image tensor
            filename(str): the image filename
Args:
            path(str):
            src_dir(str):
Args : path ( str ) : src_dir ( str ) :
def make_img_iterator_from_file(path, src_dir, image_channel_size=3):
        """
        Args:
            path(str):
            src_dir(str):

        Yields:
            img: and image tensor
            filename(str): the image filename
        """
        from PIL import Image
        from torchvision import transforms

        with codecs.open(path, "r", "utf-8") as corpus_file:
            for line in corpus_file:
                filename = line.strip()
                img_path = os.path.join(src_dir, filename)
                if not os.path.exists(img_path):
                    img_path = line

                assert os.path.exists(img_path), \
                    'img path %s not found' % (line.strip())

                if (image_channel_size == 1):
                    img = transforms.ToTensor()(
                        Image.fromarray(cv2.imread(img_path, 0)))
                else:
                    img = transforms.ToTensor()(Image.open(img_path))

                yield img, filename
def make_img_iterator_from_file ( path , src_dir , image_channel_size = 3 ) : from PIL import Image from torchvision import transforms with codecs . open ( path , "r" , "utf-8" ) as corpus_file : for line in corpus_file : filename = line . strip ( ) img_path = os . path . join ( src_dir , filename ) if not os . path . exists ( img_path ) : img_path = line assert os . path . exists ( img_path ) , 'img path %s not found' % ( line . strip ( ) ) if ( image_channel_size == 1 ) : img = transforms . ToTensor ( ) ( Image . fromarray ( cv2 . imread ( img_path , 0 ) ) ) else : img = transforms . ToTensor ( ) ( Image . open ( img_path ) ) yield img , filename