A package to return files stored in Google drive and Google Cloud Storage as a torch.utils.Dataset that can be used with the torch dataloaders.
Project description
GCP-IO
Generate PyTorch datasets from files stored in Google cloud storage and Google drive.
Installation
Run the following to install this package:
pip install gcpio
Environment Variables Required
LOG_FILE_PATH: Path to store the logs in a log file
LOG_LEVEL: LOG LEVEL(Example: INFO, DEBUG, ERROR etc)
TOKEN_PATH_GDRIVE: path to the generated token.json file
Example usage:
Google Drive:
from gcpio.gdrive import Gdrive
# Get meta data of files present in a Google Drive folder
GDRIVE = Gdrive()
files=GDRIVE.get_files_metadata(folder_id="XXXXX",page_size=500,file_type="image/png",replace_query=None) # returns a dict with keys['files','len'] where files is a list of objects from the Drive folder
# Create the torch dataset from files
GDRIVE = Gdrive()
dataset = g.create_dataset(
data_folder_id=folder_id,
labels_folder_id=folder_id,
page_size=1000,
data_file_type="image/png",
labels_file_type="text/csv",
skip_labels=skip_labels,
)
# load this dataset into torch dataloader.
dataloader = DataLoader(
dataset,
batch_size,
sampler=BatchSampler(
SequentialSampler(dataset), batch_size=batch_size, drop_last=True
),
)
#get a sample batch
samples = next(iter(dataloader))
images = []
for i in range(len(samples)):
# ignoring labels and collecting images only for verification
img, _ = samples[i]
images.append(img)
images = torch.cat(images)
grid = make_grid(images, nrow=20)
save_image(grid, f"./examples/generated_images.png")
outputs
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
gcp-io-0.0.0.2.tar.gz
(8.2 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gcp-io-0.0.0.2.tar.gz.
File metadata
- Download URL: gcp-io-0.0.0.2.tar.gz
- Upload date:
- Size: 8.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b2b0f4f3427adb5a74afc51f4043461e48bb5d40ea06ce881babbc59796b2375
|
|
| MD5 |
84d9f41b857635387a9ba0904b9aff8f
|
|
| BLAKE2b-256 |
e6a3ab3d3637dc2fd60e8ad562beb4012d3261b9333fb6b2ce2d12809a2f3ed9
|
File details
Details for the file gcp_io-0.0.0.2-py3-none-any.whl.
File metadata
- Download URL: gcp_io-0.0.0.2-py3-none-any.whl
- Upload date:
- Size: 7.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
76c442b248e703311cfa744262f08084a3727cbb3ccc0f3d1893d0a7bfce30fd
|
|
| MD5 |
447bd91005f0bee81adbdfc224019dd7
|
|
| BLAKE2b-256 |
9dfd4ff5086afcbb507f7c80e2e6378ede2513e122a72d552caf006e810b2db3
|