1/27/2020

python year month day expression using datetime

Without any separator
import datetime
datetime.datetime.now().strftime("%Y%m%d%H%M%S")
Using - as separator
import datetime
datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S")
Using _ as separator
import datetime
datetime.datetime.now().strftime("%Y_%m_%d_%H_%M_%S")

12/13/2019

python OrderDict to Dict


od = OrderedDict([('name', 'signature'), ('pose', 'Unspecified'), ('bndbox', OrderedDict([('xmin', '423'), ('ymin', '1237'), ('xmax', '785'), ('ymax', '1349')]))])
print(od)
output_dict = json.loads(json.dumps(av))
print(output_dict)





reference is here : https://stackoverflow.com/questions/20166749/how-to-convert-an-ordereddict-into-a-regular-dict-in-python3

12/08/2019

keras model summary, print out for each layers property

from keras.layers import Input
from keras.applications import VGG16
vgg_model = VGG16(weights="imagenet", include_top=False, input_tensor=Input(shape=(224, 224, 3))) #the head FC layer off

#how many layers
print(len(vgg_model.layers))



#last layer
print(vgg_model.layers[-1].name)



#print whole layer
for idx, layer in enumerate(vgg_model.layers):
print(idx+1, '-----')
print(layer.output_shape)
print(layer.name)
print('--------')



#summary of model
vgg_model.summary()



12/06/2019

using specific gpu device for TensorFlow

setting first or second gpu machine
CUDA_VISIBLE_DEVICES=0 python script_one.py
CUDA_VISIBLE_DEVICES=1 python script_two.py
another way
use first (it didn't work for me)
export CUDA_VISIBLE_DEVICE=0
./train.py
use second (it didn't work for me)
export CUDA_VISIBLE_DEVICE=1
./train.py
use both (it didn't work for me)
export CUDA_VISIBLE_DEVICE=0,1
./train.py

refer to here:
https://stackoverflow.com/questions/44135538/tensorflow-using-2-gpu-at-the-same-time

12/05/2019

monitoring gpu status in command (terminal)



pip install gpustat
>gpustat -cp




monitoring continuously
>watch -n 0.5 -c gpustat -cp --color