9/27/2021

docker swarm simple command

*install virtualbox

-+-

#install virtualbox on terminal
#osx
brew install virtualbox
#linux
sudo apt install virtualbox

-+-

 

* install docker-machine

...

#osx
curl -L https://github.com/docker/machine/releases/download/v0.16.2/docker-machine-`uname -s`-`uname -m` >/usr/local/bin/docker-machine && chmod +x /usr/local/bin/docker-machine
#linux
curl -L https://github.com/docker/machine/releases/download/v0.16.2/docker-machine-`uname -s`-`uname -m` >/tmp/docker-machine && chmod +x /tmp/docker-machine && sudo cp /tmp/docker-machine /usr/local/bin/docker-machine

...


*docker-machine

...

#docker-machine basic cmd
docker-machine ls
docker-machine rm name
docker-machine kill name
docker-machine create name

...



9/24/2021

python save & load argparse

 


refer to code:

..

from argparse import ArgumentParser
import json

parser = ArgumentParser()
parser.add_argument('--seed', type=int, default=8)
parser.add_argument('--resume', type=str, default='a/b/c.ckpt')
parser.add_argument('--surgery', type=str, default='190', choices=['190', '417'])
args = parser.parse_args()

with open('commandline_args.txt', 'w') as f:
json.dump(args.__dict__, f, indent=2)

parser = ArgumentParser()
args = parser.parse_args()
with open('commandline_args.txt', 'r') as f:
args.__dict__ = json.load(f)

print(args)

..


Thank you!

🙇ðŸŧ‍♂️

1D sequence (signal) data resampling (python)

 import numpy as np

import matplotlib.pyplot as plt
from scipy.signal import resample
from scipy.interpolate import interp1d

def ResampleLinear1D(original, targetLen):
original = np.array(original, dtype=np.float)
index_arr = np.linspace(0, len(original)-1, num=targetLen, dtype=np.float)
index_floor = np.array(index_arr, dtype=np.int) #Round down
index_ceil = index_floor + 1
index_rem = index_arr - index_floor #Remain

val1 = original[index_floor]
val2 = original[index_ceil % len(original)]
interp = val1 * (1.0-index_rem) + val2 * index_rem
assert(len(interp) == targetLen)
return interp

if __name__=="__main__":

original = np.sin(np.arange(256)/10.0)
targetLen = 100

# Method 1: Use scipy interp1d (linear interpolation)
# This is the simplest conceptually as it just uses linear interpolation. Scipy
# also offers a range of other interpolation methods.
f = interp1d(np.arange(256), original, 'linear')
plt.plot(np.apply_along_axis(f, 0, np.linspace(0, 255, num=targetLen)))

# Method 2: Use numpy to do linear interpolation
# If you don't have scipy, you can do it in numpy with the above function
plt.plot(ResampleLinear1D(original, targetLen))

# Method 3: Use scipy's resample
# Converts the signal to frequency space (Fourier method), then back. This
# works efficiently on periodic functions but poorly on non-periodic functions.
plt.plot(resample(original, targetLen))

plt.show()

9/22/2021

jupyter notebook to python py

 

run this command

>jupyter nbconvert your_notebook_name.ipynb --to python


thank you.


pytorch cuda definition

Their syntax varies slightly, but they are equivalent:

.to(name)

.to(device)

.cuda()

CPU

to('cpu')

to(torch.device('cpu'))

cpu()

Current GPU

to('cuda')

to(torch.device('cuda'))

cuda()

Specific GPU

to('cuda:1')

to(torch.device('cuda:1'))

cuda(device=1)

Note: the current cuda device is 0 by default, but this can be set with torch.cuda.set_device().

9/21/2021

write classification_report to txt file

Refer to code ^^ 

..

from sklearn.metrics import classification_report

report = classification_report(y_test_true_list, y_test_pred_list, labels=labels, target_names=target_names)

fp = open('report.txt', 'w')
fp.write(report)
fp.close()

..


Thank you.

www.marearts.com


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