keras icon indicating copy to clipboard operation
keras copied to clipboard

keras.utils.get_file function: unzip directory can't be specified

Open DaHui-BT opened this issue 1 year ago • 2 comments

  • when execute the following code, the file is download successful, but it will not unzip the stack_overflow_16k.tar.gz file into stack_overflow_16k directory, it just unzip in current directory (is ./).
  • it's right to assignment cache_subdir to stack_overflow_16k, but by doing this the ''stack_overflow_16k.tar.gz'' file is download into the directory of ''stack_overflow_16k'', i just want the unzip files in the directory of stack_overflow_16k. and the return file_directory will be not correct with stack_overflow_16k/stack_overflow_16k

how to solve this problem? thanks.

url = 'https://storage.googleapis.com/download.tensorflow.org/data/stack_overflow_16k.tar.gz'

dataset_dir = tf.keras.utils.get_file('stack_overflow_16k', origin=url, extract=True, cache_dir='.', cache_subdir='')

DaHui-BT avatar Jan 26 '24 09:01 DaHui-BT

Hi @DaHui-BT ,

I am not fully understood your question. If you want to save the url content to fname such as /stack_overflow_16k/filename , you need to create stack_overflow_16k directory and provide absolute path to argumentfname.

Or try dataset_dir = tf.keras.utils.get_file('stack_overflow_16k', origin=url, extract=True, cache_dir='.', cache_subdir='stack_overflow_16k') also seems works for your requirement.

SuryanarayanaY avatar Jan 29 '24 16:01 SuryanarayanaY

Thanks for your help, by using your code is work, it should take two steps, and you shoule specific the path which you want to load the unzip dataset. My mean is that, when run the following code, the variable dataset_dir value is ./stack_overflow_16k, but the stack_overflow_16k.tar.gz file is download in current directory (./) and then unzip in current directory. By using extract=True parameter it will unzip automaticly. I guess the zip file may have different zip choice. I can finish the work, but it will have a little bit steps, Thanks😊

url = 'https://storage.googleapis.com/download.tensorflow.org/data/stack_overflow_16k.tar.gz'

dataset_dir = tf.keras.utils.get_file('stack_overflow_16k', origin=url, extract=True, cache_dir='.', cache_subdir='')

The file directory after run the code, you can see the dataset_dir variable is not match:

---work
    |----train
    |----test

after run then code, what i want is the follows:

---work
    |----stack_overflow_16k
          |----train
          |----test

DaHui-BT avatar Feb 09 '24 09:02 DaHui-BT

Hi @DaHui-BT ,

I guess the zip file may have different zip choice. I can finish the work, but it will have a little bit steps, Thanks😊

Please feel free to raise a PR if you want ? Thanks!

SuryanarayanaY avatar Apr 05 '24 06:04 SuryanarayanaY

This issue is stale because it has been open for 14 days with no activity. It will be closed if no further activity occurs. Thank you.

github-actions[bot] avatar Apr 20 '24 01:04 github-actions[bot]

This issue was closed because it has been inactive for 28 days. Please reopen if you'd like to work on this further.

github-actions[bot] avatar May 04 '24 01:05 github-actions[bot]

Are you satisfied with the resolution of your issue? Yes No

google-ml-butler[bot] avatar May 04 '24 01:05 google-ml-butler[bot]