padding

Image padding with reflect (mirror) in Python

Image padding with reflect (mirror) in Python Question: I have an image loaded in python as an np.array with shape (7, 7). I need to apply a filtering process to the image. For this I need to apply a kernel that will convolve the 2D image (like a moving window). However, to get an output …

Total answers: 1

Python Tkinter making space between buttons (vertical)

Python Tkinter making space between buttons (vertical) Question: import tkinter as tk root = tk.Tk() root.title("Calculator") def button_write(): return data = tk.Entry(root, width=30, borderwidth=10, font="bold 20", ) data.grid(column=0, row=0, columnspan=4, padx=10, pady=10) buton1 = tk.Button(root,text="1", padx=40, pady=25, command=button_write) buton2 = tk.Button(root,text="2", padx=40, pady=25, command=button_write) buton3 = tk.Button(root,text="3", padx=40, pady=25, command=button_write) buton4 = tk.Button(root,text="4", padx=40, pady=25, …

Total answers: 1

Forming a frame of zeros around a matrix in python

Forming a frame of zeros around a matrix in python Question: I am trying to pad a matrix with zeros, but am not really sure how to do it. Basically I need to surround a matrix with an n amount of zeros. The input matrix is huge (it represents an image) Example: Input: 1 2 …

Total answers: 1

How to pad all tensors to accommodate all sizes

How to pad all tensors to accommodate all sizes Question: How do I pad two tensors of the same shape such that they both have the same size? I currently receive an error for the following code (I can’t use for loops in graph mode): def match_size(self, x, y): d = tf.maximum(tf.subtract(y.shape, x.shape), 0) x …

Total answers: 1

Why couldn't I feed a 4-tuple to nn.ReplicationPad2d()?

Why couldn't I feed a 4-tuple to nn.ReplicationPad2d()? Question: I’m applying yolov5 on kitti raw image [C, H, W] = [3, 375, 1242]. Therefore I need to pad the image so that the H and W being dividable by 32. I’m using nn.ReplicationPad2d to do the padding: [3, 375, 1242] -> [3, 384, 1248]. In …

Total answers: 2

padding='same' conversion to PyTorch padding=#

padding='same' conversion to PyTorch padding=# Question: I’m trying to convert the following Keras model code to pytorch, but am having problems dealing with padding=’same’. model = Sequential() model.add(Conv2D(64, (3, 3), input_shape=img_size)) model.add(BatchNormalization(axis=1)) model.add(Activation(‘relu’)) model.add(Dropout(0.3)) model.add(Conv2D(64, (3, 3), padding=’same’)) model.add(BatchNormalization(axis=1)) model.add(Activation(‘relu’)) model.add(MaxPooling2D(pool_size=(2,2), strides=(2,2), padding=’same’)) Which produces the following summary: Layer (type) Output Shape Param # ================================================================= …

Total answers: 6

How to unpad PKCS#7 / PKCS#5 padding?

How to unpad PKCS#7 / PKCS#5 padding? Question: I would like to for help with using the cryptography.hazmat.primitives.padding.PKCS7 Python class. After decryption I’m getting the string 453947000000197708080808, when the plaintext should be 4539470000001977. According to our development team, the plaintext should be padded with PKCS#5 padding. So I searched for this class, but could not …

Total answers: 1

Decorating Hex function to pad zeros

Decorating Hex function to pad zeros Question: I wrote this simple function: def padded_hex(i, l): given_int = i given_len = l hex_result = hex(given_int)[2:] # remove ‘0x’ from beginning of str num_hex_chars = len(hex_result) extra_zeros = ‘0’ * (given_len – num_hex_chars) # may not get used.. return (‘0x’ + hex_result if num_hex_chars == given_len else …

Total answers: 8

Encrypt & Decrypt using PyCrypto AES 256

Encrypt and decrypt using PyCrypto AES-256 Question: I’m trying to build two functions using PyCrypto that accept two parameters: the message and the key, and then encrypt/decrypt the message. I found several links on the web to help me out, but each one of them has flaws: This one at codekoala uses os.urandom, which is …

Total answers: 15