Posts

Showing posts from March, 2020

Java Learning

Java 注解: Java 语言中的类、方法、变量、参数和包都可以被标注。 Java标注可以通过反射获取标注内容。 内置的注解: Java定义了一套注解,共有7个,3个在java.lang中,剩下的4个在java.lang.annotation中。 @override--检查该方法是否是重写方法。如果发现其父类,或者引用的接口并没有该方法时,会报编译警告。 @Deprecated--标记过时方法。如果使用该方法,会报编译警告。 @SupperessWarning--指示编译器去忽略注解中声明的警告。 @Retention--标识这个注解应该怎么保存,是只在代码中,还是编入class文件中,或者是在运行时间可以通过反射访问。 @Documented--标记这些注解是否包含在用户文档中。 @Target--标记这个注解应该是哪种Java成员。 @Inherited--标记这个注解是继承于哪个注解类。

Daily-coding-problem #101

# This problem was asked by Alibaba. # Given an even number (greater than 2), return two prime numbers whose sum will be equal to the given number. def is_prime(n, primes):     for p in primes:         if n == p:             return True         if not n%p == 0:             return False     return True def get_primes(num):     limit = num//2     primes = list()     candidates = list()     for i in range(2, limit+1):         if is_prime(i, primes):             primes.append(i)             candidates.append((i, num-i))     new_candidates = list()     for p1, p2 in candidates[::-1]:         if is_prime(p2, primes):             primes.append(p2)     ...

Image Similarity using Deep Ranking

Image
Image similarity: the measure of how similar two images are. In other words, it quantifies the degree of similarity between intensity patterns in two images. Triplet: a triplet contains a query image, a positive image and a negative image. How to measure the similarity of two images? L1-norm: Manhattan distance L2-norm: Euclidean distance Loss function: The whole deep ranking architecture can be thought of as a function that would map the image to a point in the Euclidean space. The goal is to learn an embedding function that assigns smaller distance to more similar images. D(f(pi), f(pi+)) < D(f(pi), f(pi-)) <pi, pi+, pi-> such that r(pi, pi+) > r(pi,pi-) f is the embedding function that would map the image to a vector. pi is the query image, pi+ is the positive image, pi- is the negative image and r is the similarity distance between two images. The hinge loss for the triplet is defined as: l(pi, pi+, pi-) = max{0, g+D(f(pi), f(pi+)) - D(f(pi),f(pi-...

Python Notes

zip: returns a list of tuples, where the i-th tuple contains the i-th element from each of the argument sequences or iterables. a = [1, 2, 3] b = ['a', 'b', 'c'] for i, j in zip(a, b):      print(i,j) =>1 a =>2 b =>3 c Python __repr__() function returns the object representation. It could be any valid python expression such as tuple, dictionary, string etc.  id(object): return the "identity" of an object. This is an integer which is guaranteed to be unique and constant for this object during its lifetime. Two objects with non-overlapping lifetimes may have the same id() value. hasattr() The hasattr() method returns true if an object has the given named attribute and false if it does not. hasattr(object, name) PIL. Image.resize(size, resample = 0) returns a resized copy of this image Parameters:  -size: the requested size in pixels, as a 2-tuple -resample: an optional resampling filter. This can be one of PIL.I...

Pytorch Notes

torch.nn.functioanl.adaptive_avg_pool2d(input, output_size) Applies a 2D adaptive average pooling over an input signal composed of several input planes. torch.nn.functional.adaptive_avg_pool3d(input, output_size) Applies a 3D adaptive average pooling over an input signal composed of several input planes Class: torch.nn.Parameter A kind of Tensor that is to be considered a module parameter. parameters: data(Tensor) torch.nn.functional.interpolate(input, size, scale_factor, mode= 'nearest', align_corners) Down/up samples the input to either the given size or the given scale_factor. The algorithm used for interpolation is determined by mode. torch.cat(tensors, dim = 0, out = None) concatenates the given of seq tensors in the given dimension. All tensors must be either have the same shape or be empty.