一、20200729
1、image和annots的数据类型要统一,如image,annots设为np.float32。在具体函数中,输入和输出的数据类型要保持一致,中间具体应用再改变数据类型。
2、仿射变换可以用PIL的transform(),设置Image.AFFINE来便捷实现
img = img.transform(img.size, Image.AFFINE, (1, magnitude, 0, 0, 1, 0), Image.BICUBIC, fillcolor=fillcolor)
其中相关参数可以参考
https://cloud.tencent.com/developer/news/627475
。
3、cv2.imread读入是BGR,和plt.imread不同,需要转换,否则图片会泛蓝。opencv和skimage的resize接口不同。同时,图片的坐标系是:
0 ------> x
|
|
|
v
y
因此仿射变换的时候要注意。
4、torch中可以用stack来堆叠取出的元素,不影响反向传播。
二、0813-IND5003
1. how to open project in jupyter notebook
Use the anaconda prompt to set the enviroment and input: jupyter notebook xx, xx is the project dir address
2. slice in str
python locate to the begin and search next element by step until end. In this situation, the end was not specify, so python will search until 0.
3. type in python
lists, which are defined with [ ]. Lists are mutable.
tuples, which are defined with ( ). Tuples are immutable.
dictionaries, which are defined with { }. Dictionaries have keys and items. They are also mutable.
str is immutable
4. format print
for x in x_range:
print(f'{x} squared: {x ** 2}, cubed: {x ** 3}.')
print('{}, squard:{}, cubed:{}'.format(x, x**2, x**3))
for key, item in comics.items():
print(f"Here's the key '{key}',")
print(f"and the associated item '{item}'.")
5. regular expression
import re
p = re.compile('a[bcd]*b')
# match one of [bcd] zero or more times
# + one or more times
# {3,} math 3 times
# start with a and end with b
out = p.match(“abcbd”)
out.group() # contains the matched string
re2 = re.compile('nus.edu.sg$')
# $ match the end of the text
[email_adds[x] for x,y in enumerate(email_adds) if re2.search(y) is not None]
y = ['a', 'b', 'd']
list(map(lambda x: 'You typed ' + x, y))
p2 = re.compile('^.*(?=@)')
# ^ begining
# .* anything zero or any times
# (?=@) until @