9/21/2021

python pil change dpi without save file

 


look at the code! ^^

..

#load image
tif_path = './input_img.tif'
#open image
pil_image = Image.open(tif_path)
#change dpi in memory
temp_mem_file = BytesIO()
page.save(temp_mem_file, format='png', dpi=(100,100))
#save it to pil
temp_mem_file.seek(0)
pil_image = Image.open(temp_mem_file)
#do it someting
#..
#save file
pil_image.save('./output.png')
#www.marearts.com
#study.marearts.com

..


Thank you.


9/20/2021

convert numpy.ndarray object to float


*Here is object dtype numpy.ndarray
print(oneD_pt.dtype, type(oneD_pt), oneD_pt)
> object <class 'numpy.ndarray'> [3 2 1 2 2] 

* convert float dtype numpy.ndarray
oneD_pt=oneD_pt.astype('float')
print(oneD_pt.dtype, type(oneD_pt), oneD_pt)
> float64 <class 'numpy.ndarray'> [3. 2. 1. 2. 2.]


thank you.

python argparse simple example

 

It's useful to save hyper parameter for machine learning


import argparse

paser = argparse.ArgumentParser()

args = paser.parse_args("")

args.batch_size=10

args.epoch=10


Thank you.


vs code server failed to start


try to kill the server which you want access and try to access again


1 .ctrl-shift-p and choose:
2. Remote-SSH: kill VS Code Server on Host...
3. access remote again


Thank you.


9/07/2021

nginx.conf, set to accept last path and poxy it.

 


ex)

www.xxx.yy/aaa/ping

www.xxx.yy/bbb/ping

Those urls will go to /ping proxy.


location ~ ^/.*/(ping|invocations) {
rewrite ^/.*/(.*)$ /$1 last;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://gunicorn/$1;
}

9/01/2021

AWS dynamoDB safe searching way, search item by scan and get it by paginator.

 refer to follow code

--

import boto3

dynamo_client = boto3.client('dynamodb')

def Search_Item(TABLE_NAME, uid):
paginator = dynamo_client.get_paginator('scan')
operation_parameters = {
'TableName': TABLE_NAME,
'FilterExpression': 'UID = :search',
'ExpressionAttributeValues': {
':search': {'S': uid},
}
}
page_iterator = paginator.paginate(**operation_parameters)
return page_iterator

UID_list = []
TABLE_NAME ='example_Table'
UID ='example_uid'

page_iterator = Search_Item(TABLE_NAME, UID)
for page in page_iterator:
for item in page['Items']:
UID_list.append(item['UID']['S'])

--


Thank you.

www.marearts.com