<s> """<STR_LIT>""" <EOL> import os <EOL> import numpy as np <EOL> from PIL import Image <EOL> import tarfile <EOL> from glob import glob <EOL> from sklearn . externals . joblib import Memory <EOL> from sklearn . datasets . base import Bunch <EOL> from . base import download , get_dataset_dir <EOL> def check_fetch_asirra ( ) : <EOL> url = "<STR_LIT>" <EOL> partial_path = get_dataset_dir ( "<STR_LIT>" ) <EOL> full_path = os . path . join ( partial_path , "<STR_LIT>" ) <EOL> if not os . path . exists ( partial_path ) : <EOL> os . makedirs ( partial_path ) <EOL> if not os . path . exists ( full_path ) : <EOL> download ( url , full_path , progress_update_percentage = <NUM_LIT:1> ) <EOL> files_path = os . path . join ( partial_path , "<STR_LIT>" ) <EOL> if not os . path . exists ( files_path ) : <EOL> tar_obj = tarfile . TarFile ( full_path , '<STR_LIT:r>' ) <EOL> tar_obj . extractall ( partial_path ) <EOL> tar_obj . close ( ) <EOL> return partial_path <EOL> def _fetch_asirra ( partial_path , image_count = <NUM_LIT:1000> ) : <EOL> files_path = os . path . join ( partial_path , '<STR_LIT>' ) <EOL> cat_files_path = os . path . join ( files_path , '<STR_LIT>' , '<STR_LIT>' ) <EOL> dog_files_path = os . path . join ( files_path , '<STR_LIT>' , '<STR_LIT>' ) <EOL> def get_file_number ( f ) : <EOL> fname = os . path . split ( f ) [ - <NUM_LIT:1> ] <EOL> return int ( fname [ : - <NUM_LIT:4> ] ) <EOL> cat_files = sorted ( glob ( cat_files_path ) , key = get_file_number ) <EOL> dog_files = sorted ( glob ( dog_files_path ) , key = get_file_number ) <EOL> X = np . zeros ( ( image_count , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:3> ) , dtype = '<STR_LIT>' ) <EOL> y = np . zeros ( image_count ) <EOL> count = <NUM_LIT:0> <EOL> for f in cat_files : <EOL> try : <EOL> im = Image . open ( f , '<STR_LIT:r>' ) <EOL> X [ count ] = np . array ( im . resize ( ( <NUM_LIT> , <NUM_LIT> ) ) ) <EOL> y [ count ] = <NUM_LIT:0.> <EOL> count += <NUM_LIT:1> <EOL> except : <EOL> continue <EOL> if count >= image_count // <NUM_LIT:2> : <EOL> break <EOL> for f in dog_files : <EOL> try : <EOL> im = Image . open ( f , '<STR_LIT:r>' ) <EOL> X [ count ] = np . array ( im . resize ( ( <NUM_LIT> , <NUM_LIT> ) ) ) <EOL> y [ count ] = <NUM_LIT:1.> <EOL> count += <NUM_LIT:1> <EOL> except : <EOL> continue <EOL> if count >= image_count : <EOL> break <EOL> return X , y <EOL> def fetch_asirra ( image_count = <NUM_LIT:1000> ) : <EOL> """<STR_LIT>""" <EOL> partial_path = check_fetch_asirra ( ) <EOL> m = Memory ( cachedir = partial_path , compress = <NUM_LIT:6> , verbose = <NUM_LIT:0> ) <EOL> load_func = m . cache ( _fetch_asirra ) <EOL> images , target = load_func ( partial_path , image_count = image_count ) <EOL> return Bunch ( data = images . reshape ( len ( images ) , - <NUM_LIT:1> ) , <EOL> images = images , target = target , <EOL> DESCR = "<STR_LIT>" ) </s>
