编程TRICK

一、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 @

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值