Yaohong

为了真相不惜被羞辱

How to Read a Image in Python

How to Read a Image in Python There are three ways to read a image, the codes is showing below. image_path = "fasterRCNN/faster-rcnn-keras-master/img/street.jpg"; from PIL import Image import numpy as np image = Image.open(image_path) # RGB tmp_image = np.array(image) print("PIL open shape:",tmp_image.shape, tmp_image) # load with cv2 import cv2 image = cv2.imread(image_path) # mode: BGR print("cv2 imread shape:", image.shape) # (width,height,channel) # load with matplotlib import matplotlib.image as mpimg image = mpimg.

Differences On Numpyp.Floor And Python Int method.md

Differences On Numpyp.Floor And Python Int method.md numpy.floor Return the floor of the input. The floor of the scalar x is the largest integer i, such that i <= x; np.floor() will not change its data type; Example: import numpy as np tmp_list = list([-3.3, -2.22, -1.56, -0.56, 0.56, 1.56, 2.22, 3.33]) tmp_list = np.array(tmp_list) print("type(tmp_list[0]):", type(tmp_list[0]) ) print("type(np.floor(tmp_list)[0]):", type(np.floor(tmp_list)[0]) ) print("np.floor(tmp_list):", np.floor(tmp_list)) # Output: # type(tmp_list[0]): <class 'numpy.float64'> # type(np.

Averaging histograms

Averaging histograms An image histogram is the number of each pixel value, which is displayed in the graph. x axis of the graph is pixel value, range from 0 to 255; y axis of the graph is the number of this pixel value; 1.How to averaging histograms? Our goal is to generate a new image with a more even histogram distribution. 1.1 An equation The accumulated value of the histogram

How does numpy add two arrays with different shapes?

How does numpy add two arrays with different shapes? Numpy has a add method which add two numpy array. Arithmetic operation + does the same thing as Numpy.add; 1.Add a same shapes array Let’s see a example. import numpy as np list1 = np.array([1, 2, 3]); list2= np.array([10, 20, 30]); print("list1:",list1,"list2:",list2); # Print: list1: [1 2 3] list2: [10 20 30] added_list = list1 + list2; print("added_list.shape:",added_list.shape,"\nadded_list:",added_list); # Print: # added_list.

Understanding Transpose

Understanding Numpy Transpose 1.Transpose is to switch the row and column indices of the matrix A; x = np.arange(8).reshape((4,2)) print(x) print(x.T) # output: # [[0 1] # x # [2 3] # [4 5] # [6 7]] # [[0 2 4 6] # x.T # [1 3 5 7]] x = np.arange(9).reshape((3,3)) print(x) print(x.T) print(x.shape, x.T.shape) # output: # [[0 1 2] # [3 4 5] # [6 7 8]] # [[0 3 6] # [1 4 7] # [2 5 8]] x = np.

What do `*args` and `**kwargs` mean in python function?

What do *args and **kwargs mean in python function? *args means we can pass an arbitrary number of arguments to the function; Similarly, **kwargs allow we pass many key=value argument to the function; *args *args iterable: def my_sum(*args): result = 0 # Iterating over the Python args tuple for x in args: result += x return result print(my_sum(1, 2, 3)) # output: 6 The * is a unpacking operator; def print_three_things(a, b, c): print( 'a = {0}, b = {1}, c = {2}'.

How Keras add two layers?

How Keras add two layers? tf.keras.layers.add() method can add two layer? What it do is sum the values of corresponding positions in two layers. For example: input_shape = (1,2,3) import tensorflow as tf tf.enable_eager_execution() print("----------x1 tensor-----------") x1 = tf.random.uniform(input_shape, maxval=10, dtype=tf.dtypes.int32) tf.print(x1); print("----------x2 tensor-----------") x2 = tf.random.uniform(input_shape, maxval=10, dtype=tf.dtypes.int32) tf.print(x2); print("----------add 2 tensors-----------") y = tf.keras.layers.add([x1,x2]) tf.print(y); Output: ———-x1 tensor———– [[[7 6 1] [5 7 2]]] ———-x2 tensor———– [[[0 7 8] [2 9 6]]] ———-add 2 tensors———– [[[7 13 9] [7 16 8]]]

Understanding Numpy expand_dims

Inserting 1 into the shape brackets base on the axis value

Understanding Numpy expand_dims Shape (n,)(n is a number) means it has only one dimension. The number of values is shape brackets represents the number of dimensions. import numpy as np arr = np.array([1,2,3,4,5]); print("arr shape: ",arr.shape) print("arr shape: ",arr) arr2 = np.expand_dims(arr, 0); print("expand_dims axis=0, shape:",arr2.shape) print("expand_dims axis=0, arr2:",arr2) arr2 = np.expand_dims(arr, 1); print("expand_dims axis=1, shape:",arr2.shape) print("expand_dims axis=1, arr2:",arr2) output: arr shape: (5,) arr shape: [1 2 3 4 5] expand_dims axis=0, shape: (1, 5) expand_dims axis=0, arr2: [[1 2 3 4 5]] expand_dims axis=1, shape: (5, 1) expand_dims axis=1, arr2: [[1] [2] [3] [4] [5]] numpy.

Sed

Sed sed is a steam editor. sed treats multiple input files as one long stream. The full format for invoking sed is: sed OPTIONS... [SCRIPT] [INPUTFILE...] Some common OPTIONS: -n to suppress output, sed -n '45p' file.txt this command prints only line 45 of input file; -e options are used to specify a script expression, such as sed -e 's/hello/world/' input.txt > output.txt; -f specify a script file, such as sed -f myscript.

Simple Tree command

Simple Tree command Using the follow command can view current folder tree: find . -print| sed -e 's;[^/]*/;|____;g;s;____|; |;g' output $ find . -print| sed -e 's;[^/]*/;|____;g;s;____|; |;g' . |____composer.lock |____LICENSE |____README.md |____.gitignore |____build-phar.php |____.git | |____config | |____objects ... Below command only descend at most 2 directory levels: find . -maxdepth 2 -e -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g' REFERENCE Using a Mac Equivalent of Unix “tree” Command to View Folder Trees at Terminal

Categorical Crossentropy源码分析

Categorical Crossentropy源码分析 Source: import tensorflow as tf import numpy as np sess = tf.InteractiveSession() print("--------output-----------") target = tf.constant([1., 0., 0., 0., 1., 0., 0., 0., 1.], shape=[3,3]) print("target: \n",target.eval()) output = tf.constant([.9, .05, .05, .05, .89, .06, .05, .01, .94], shape=[3,3]) print("output:\n",output.eval()) loss = tf.keras.backend.categorical_crossentropy(target, output) print("loss: \n",loss.eval()) # Output: [0.10536 0.11653 0.06188] 官方

如何计算RNN和LSTM的参数数量?

如何计算RNN和LSTM的参数数量? Environment: python version: 3.7.4 pip version: 19.0.3 numpy version:1.19.4 matplotlib version:3.3.3 tensorflow version:1.14.0 keras version:2.1.5 代码如下: from keras.layers import SimpleRNN from keras.models import Model from keras import Input inputs = Input((None, 5)) simple_rnn = SimpleRNN(4) output = simple_rnn(inputs) # The output has shape `[32, 4]`. model = Model(inputs,output)

创建一个简单的RNN网络

创建一个简单的RNN网络 Environment: python version: 3.7.4 pip version: 19.0.3 numpy version:1.19.4 matplotlib version:3.3.3 tensorflow version:1.14.0 keras version:2.1.5 代码如下: import keras from keras import backend as K from keras.layers import RNN class MinimalRNNCell(keras.layers.Layer): def __init__(self, units,use_bias = True, **kwargs): self.units = units self.state_size = units self.use_bias = use_bias super(MinimalRNNCell, self).__init__(**kwargs) def build(self, input_shape): self.kernel = self.add_weight(shape=(input_shape[-1], self.units),

Config Github with SSH

Config Github with SSH Generating a new SSH key 1.Open TerminalTerminalGit Bash. 2.Paste the text below, substituting in your GitHub email address. $ ssh-keygen -t ed25519 -C "your_email@example.com" 3.Then you’re prompted to do something, press Enter. Then the keys will be saved under ~/.ssh folder. You can use ls -al ~/.ssh command to see them. LOG: $ ssh-keygen -t ed25519 -C "my_email@example.com" Generating public/private ed25519 key pair. Enter file in which to save the key (/c/Users/myusername/.

Quickly host your hugo web on Gitlab

Quickly host your hugo web on Gitlab Quickly host your hugo web on gitlab. 1.Login gitlab Gitlab 2.click new project after login Click Create from template in Create new project and use “Hugo template” In this example, my project name is: testPage Now you can see your username on Project URL, for example, mine is https://gitlab.com/RhysYao/, and username is RhysYao which will be used later. 3.Edit config.toml and commit Change the baseurl https://pages.

telnet

Telnet telnet host post 示例: [yaohong@host ~]# telnet www.baidu.com 80 Trying 14.215.177.38... Connected to www.baidu.com. Escape character is '^]'. 出现Connected to表示连接上主机; [yaohong@host ~]# telnet www.baidu.com 882 Trying 14.215.177.38... telnet: connect to address 14.215.177.38: Connection timed out Trying 14.215.177.39... 没有出现Connect

如何计算一个BatchNormalization的参数?

Batch参数=前一层卷积数量x4

如何计算一个BatchNormalization的参数? # Environment: # OS macOS Catalina 10.15.6 # python 3.7 # pip 20.1.1 # tensorflow 1.14.0 # Keras 2.1.5 from keras.models import Sequential from keras.layers import Conv2D,BatchNormalization model = Sequential(); #

双线插值是什么?

邻近四个点,插入点距哪个点近,该点对插值的影响更大。

双线插值是什么? 图像处理中,有时我们需要放大图片,比如原来图片宽高是300*300px,如果要在500*500的屏幕上展示,这时一种方法就是

Understand limits to infinity

When `x->∞`, `1/x` appoachs zero, but is never equal zero!

Understanding limits to infinity When x->∞, what is the exact number of x? We don’t know, x is undefined. ∞ is not a number, is a idea of having a greater number than you give. When x->∞, 1/x appoachs zero, but is never equal zero! When n -> ∞, does sin(1/n) / (1/n) have meaning? I used to thought 1/n = 0 while n->∞, but 0 cannot be divided, So I was confused.

SSLCertVerificationError报错

双击执行Applications > Python3.6 下的Install Certificates.command

SSLCertVerificationError报错 Error: ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1091) Solution: 环境:Mac Macintosh HD > Applications > Python3.6 (或者其它安装python目录) 然