Python syntax fragmentation (2 ),
1. Usage of super
If a subclass overrides a method, the subclass generally calls the override method. Sometimes super is used to call the method of the parent class.
Super (DetectionModelHelper, self). _ init _ (** kwargs) # Call the initialization function of the parent class
2. collections. namedtuple
Common tuple is accessed through index, and named index can be accessed through name
FpnLevelInfo = collections.namedtuple( 'FpnLevelInfo', ['blobs', 'dims', 'spatial_scales'])aa = FpnLevelInfo( blobs=('res5_2_sum', 'res4_5_sum', 'res3_3_sum', 'res2_2_sum'), dims=(2048, 1024, 512, 256), spatial_scales=(1. / 32., 1. / 16., 1. / 8., 1. / 4.) )print aa.blobs #('res5_2_sum', 'res4_5_sum', 'res3_3_sum', 'res2_2_sum')print aa.dims #(2048, 1024, 512, 256)
3. isinstance ()
Isinstance is used to determine the type. Different from type (), isinstance determines that the subclass and parent class objects are of the same class, but the type is considered to be different classes, and other similar
proposal_files = ()isinstance(proposal_files, basestring) #False
4
Python *, where a * represents list or tuple, and ** represents map or dic (dictionary)
[get_roidb(*args) for args in zip(dataset_names, proposal_files)]
It indicates that the parameter input to get_roidb is a list or tuple. Because the zip function is used, it indicates that the input is tuple.
5 extend and append
The list has two functions: extend and append, all of which are appended to the list. append appends the appended element as a target appended to the back, extend adds each element of the append object to the end of the original object.
Differences between the two
6. np. where
fg_inds = np.where(overlaps >= cfg.TRAIN.FG_THRESH)[0]
7. collection deque
Dual-end queue, both ends can perform extend and pop operations
from collections import dequea = deque([1,2,3])a.extendleft([1,2,3])a.popleft()
Deque also has a rotate operation, which can be used for cyclic shift.
a.rotate(-2)
8. Python uuid generates a random identifier with no specific meaning. Generally, uuid1 (), uuid3 (), uuid4 (), and uuid5 ()
uuid.uuid4() #UUID('bdc44ad5-b2cc-4e36-a061-afe4496ac5b7')
9. Python Multithreading
A better explanation of multithreading: https://www.imooc.com/article/16198
10. OrderedDict
The dictionary output in Python is unordered, but in collections, an element in the dictionary can be output in order, that is, OrderedDict ()
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger. Http://blog.csdn.net/u013548568/article/details/79406741