python dict keys to list

 refer to example code

..

dictionary = {"a": 1, "b": 2, "c": 3}
key_iterable = dictionary.keys()
key_list = list(key_iterable)
print(key_list)

..



www.marearts.com

Thank you. 🙇🏻‍♂️

get pdf file list in aws s3 bucket

Get all pdf file list in s3 bucket.

Change extension file name properly.


..

#s3 client
import boto3
from botocore.exceptions import ClientError

s3_client = boto3.client('s3')
ACCESS_KEY = 'key'
SECRET_KEY = 'secret_key'
s3_client = boto3.client(
's3',
aws_access_key_id=ACCESS_KEY,
aws_secret_access_key=SECRET_KEY,
region_name = 'eu-west-1'
)

#get pdf list
paginator = s3_client.get_paginator('list_objects_v2')
pages = paginator.paginate(Bucket='bucket_name')

cnt = 0
pdf_list = []
for page in pages:
for obj in page['Contents']:
#get file name
fn = obj['Key']
#check extension name
if fn[-3:] == 'pdf':
pdf_list.append(fn)
#print count, filename
print(f'cnt:{cnt}, fn:{fn}')
#increase count
cnt += 1

..


other code for search bucket + subfolder

..

operation_parameters = {'Bucket': 'bucket_name','Prefix': 'sub_folder_name'}
pages = paginator.paginate(**operation_parameters)

..


www.marearts.com

thank you.

🙇🏻‍♂️

flatten, unflatten Pytorch, torch, tensor reshape

 flatten -> unflatten


..

#batch, ch, row, col
input_size=torch.empty(10, 1, 256, 256)
print('input shape: ',input_size.shape)

#flatten batch, ch*row*col
reshape = torch.flatten(input_size, start_dim=1)
# reshape = input_size.reshape(-1, 1*256*256)
print('reshape or flatten: ',reshape.shape)

#unflatten batch, ch, row, col
reshape = reshape.reshape(-1,1,256,256)
print('unflatten: ',reshape.shape)

..


input shape:  torch.Size([10, 1, 256, 256])
reshape or flatten:  torch.Size([10, 65536])
unflatten:  torch.Size([10, 1, 256, 256])


Thank you.
🙇🏻‍♂️