本文整理汇总了Python中numpy.pad函数的典型用法代码示例。如果您正苦于以下问题:Python pad函数的具体用法?Python pad怎么用?Python pad使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pad函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: eval
def eval(self, data, label, lens):
predictions = []
vals = []
for i in range(data.shape[0]/self.batch_size):
D = data[range(self.batch_size*i,self.batch_size*(i+1))]
L = label[range(self.batch_size*i,self.batch_size*(i+1))]
if lens is not None:
l = lens[range(self.batch_size*i,self.batch_size*(i+1))]
feed_dict={self.dataset:D, self.labels:L, self.lengths:l}
else:
feed_dict={self.dataset:D, self.labels:L}
predictions.extend(self.sess.run(self.correct_prediction, feed_dict))
vals.extend(self.sess.run(tf.argmax(self.logits,1), feed_dict))
## DO THE EXTRA
last_chunk = self.batch_size*(i+1)
gap = self.batch_size - (data.shape[0] - last_chunk)
D = np.pad(data[last_chunk:], ((0,gap),(0,0)), mode='constant', constant_values=0)
L = np.pad(label[last_chunk:], ((0,gap),(0,0)), mode='constant', constant_values=0)
if lens is not None:
l = np.pad(lens[last_chunk:], (0,gap), mode='constant', constant_values=0)
feed_dict={self.dataset:D, self.labels:L, self.lengths:l}
else:
feed_dict={self.dataset:D, self.labels:L}
predictions.extend(self.sess.run(self.correct_prediction, feed_dict)[:self.batch_size - gap])
vals.extend(self.sess.run(tf.argmax(self.logits,1), feed_dict)[:self.batch_size - gap])
print vals
## PRINT THE PREDICTONS
return 100.0*sum(predictions)/len(predictions)
开发者ID:ybisk,项目名称:GroundedLanguage,代码行数:31,代码来源:Train.py
示例2: SMeval
def SMeval(self, DWi, DU, Dlens, DWj, keep_predictions=False):
"""
Runs eval on dev/test data with the option to return predictions or performance
"""
predictions = []
for i in range(len(DWi)/self.batch_size):
batch_range = range(self.batch_size*i,self.batch_size*(i+1))
wi = DWi[batch_range]
wj = DWj[batch_range]
U = DU[batch_range]
lens = Dlens[batch_range]
feed_dict = {self.cur_world: wi, self.next_world: wj, self.inputs: U, self.lengths: lens}
if keep_predictions:
predictions.extend(self.sess.run(tf.argmax(self.logits,1), feed_dict))
else:
predictions.extend(self.sess.run(self.correct_prediction, feed_dict))
## Grab the extras
last_chunk = self.batch_size*(i+1)
gap = self.batch_size - (len(DWi) - last_chunk)
wi = np.pad(DWi[last_chunk:], ((0,gap),(0,0), (0,0), (0,0)), mode='constant', constant_values=0)
wj = np.pad(DWj[last_chunk:], ((0,gap),(0,0)), mode='constant', constant_values=0)
U = np.pad(DU[last_chunk:], ((0,gap),(0,0)), mode='constant', constant_values=0)
lens = np.pad(Dlens[last_chunk:], ((0,gap)), mode='constant', constant_values=0)
feed_dict = {self.cur_world: wi, self.next_world: wj, self.inputs: U, self.lengths: lens}
if keep_predictions:
predictions.extend(self.sess.run(tf.argmax(self.logits,1), feed_dict)[:self.batch_size - gap])
return predictions
else:
predictions.extend(self.sess.run(self.correct_prediction, feed_dict)[:self.batch_size - gap])
return 100.0*sum(predictions)/len(predictions)
开发者ID:ybisk,项目名称:GroundedLanguage,代码行数:31,代码来源:Evaluation.py
示例3: padding
def padding(nframes, x, y):
""" Dirty hacky padding for a minimum of nframes """
b_a = (nframes - 1) / 2 # before // after
x_2 = copy.deepcopy(x)
on_x_2 = False
x_f = zeros((x.shape[0], nframes * x.shape[1]), dtype='float32')
for i in xrange(x.shape[0]):
if y[i] == '!ENTER[2]' and y[i-1] != '!ENTER[2]': # TODO general case
on_x_2 = not on_x_2
if on_x_2:
x_2[i - b_a:i, :] = 0.0
else:
x[i - b_a:i, :] = 0.0
if i+b_a < y.shape[0] and '!EXIT' in y[i] and not '!EXIT' in y[i+b_a]:
# TODO general case
if on_x_2:
x_2[i+b_a:i+2*b_a+1, :] = 0.0
else:
x[i+b_a:i+2*b_a+1, :] = 0.0
if on_x_2:
x_f[i] = pad(x_2[max(0, i - b_a):i + b_a + 1].flatten(),
(max(0, (b_a - i) * x.shape[1]),
max(0, ((i+b_a+1) - x.shape[0]) * x.shape[1])),
'constant', constant_values=(0, 0))
else:
x_f[i] = pad(x[max(0, i - b_a):i + b_a + 1].flatten(),
(max(0, (b_a - i) * x.shape[1]),
max(0, ((i+b_a+1) - x.shape[0]) * x.shape[1])),
'constant', constant_values=(0, 0))
return x_f
开发者ID:RolT,项目名称:timit_tools,代码行数:30,代码来源:prep_timit.py
示例4: paddingAnswers
def paddingAnswers(answerSheet1, blankSheet1):
numRowsA, numColsA, numBandsA, dataTypeA = ipcv.dimensions(answerSheet1)
numRowsB, numColsB, numBandsB, dataTypeB = ipcv.dimensions(blankSheet1)
print numRowsB, numColsB
if numBandsA == 3:
answerSheet = cv2.cvtColor(answerSheet1, cv.CV_BGR2GRAY)
elif numBandsA == 1:
answerSheet = answerSheet1
if numBandsB == 3:
blankSheet = cv2.cvtColor(blankSheet1, cv.CV_BGR2GRAY)
elif numBandsB == 1:
blankSheet = blankSheet1
pad = numpy.absolute(numRowsA - numColsA)/2.0
maxCount = numpy.max(blankSheet)
if (numRowsA-numColsA) % 2 != 0:
answerSheet = numpy.pad(answerSheet, ((0,0),(pad,pad+1)), 'constant', constant_values=((maxCount, maxCount),(maxCount,maxCount)))
elif (numRowsA-numColsA) % 2 == 0:
answerSheet = numpy.pad(answerSheet, ((0,0),(pad,pad)), 'constant', constant_values=((maxCount, maxCount),(maxCount,maxCount)))
pad1 = numpy.absolute(numRowsB - numColsB)/2.0
maxCount = numpy.max(blankSheet)
if (numRowsB-numColsB) % 2 != 0:
blankSheet = numpy.pad(blankSheet, ((0,0),(pad1,pad1+1)), 'constant', constant_values=((maxCount, maxCount),(maxCount,maxCount)))
elif (numRowsA-numColsA) % 2 == 0:
blankSheet = numpy.pad(blankSheet, ((0,0),(pad1,pad1)), 'constant', constant_values=((maxCount, maxCount),(maxCount,maxCount)))
return answerSheet, blankSheet
开发者ID:jordanwesthoff,项目名称:scantron,代码行数:32,代码来源:paddingAnswers.py
示例5: tile_images_make_tiles
def tile_images_make_tiles(data, padsize=1, padval=0, width=None, highlights = None):
height,width = get_tiles_height_width(data.shape[0], desired_width = width)
# Old one-way padding, no highlights
#padding = ((0, width*height - data.shape[0]), (0, padsize), (0, padsize)) + ((0, 0),) * (data.ndim - 3)
#data = np.pad(data, padding, mode='constant', constant_values=(padval, padval))
# New two-way padding with highlights
#padding = ((0, width*height - data.shape[0]), (padsize, padsize), (padsize, padsize)) + ((0, 0),) * (data.ndim - 3)
#print 'tile_images: data min,max =', data.min(), data.max()
#padder = SmartPadder()
##data = np.pad(data, padding, mode=jy_pad_fn)
#data = np.pad(data, padding, mode=padder.pad_function)
#print 'padder.calls =', padder.calls
# New new way, two-way padding with highlights
if highlights is not None:
assert len(highlights) == data.shape[0]
padding = ((0, width*height - data.shape[0]), (padsize, padsize), (padsize, padsize)) + ((0, 0),) * (data.ndim - 3)
# First pad with constant vals
try:
len(padval)
except:
padval = tuple((padval,))
assert len(padval) in (1,3), 'padval should be grayscale (len 1) or color (len 3)'
if len(padval) == 1:
data = np.pad(data, padding, mode='constant', constant_values=(padval, padval))
else:
data = np.pad(data, padding, mode='constant', constant_values=(0, 0))
for cc in (0,1,2):
# Replace 0s with proper color in each channel
data[:padding[0][0], :, :, cc] = padval[cc]
if padding[0][1] > 0:
data[-padding[0][1]:, :, :, cc] = padval[cc]
data[:, :padding[1][0], :, cc] = padval[cc]
if padding[1][1] > 0:
data[:, -padding[1][1]:, :, cc] = padval[cc]
data[:, :, :padding[2][0], cc] = padval[cc]
if padding[2][1] > 0:
data[:, :, -padding[2][1]:, cc] = padval[cc]
if highlights is not None:
# Then highlight if necessary
for ii,highlight in enumerate(highlights):
if highlight is not None:
data[ii,:padding[1][0],:,:] = highlight
if padding[1][1] > 0:
data[ii,-padding[1][1]:,:,:] = highlight
data[ii,:,:padding[2][0],:] = highlight
if padding[2][1] > 0:
data[ii,:,-padding[2][1]:,:] = highlight
# tile the filters into an image
data = data.reshape((height, width) + data.shape[1:]).transpose((0, 2, 1, 3) + tuple(range(4, data.ndim + 1)))
data = data.reshape((height * data.shape[1], width * data.shape[3]) + data.shape[4:])
data = data[0:-padsize, 0:-padsize] # remove excess padding
return (height,width), data
开发者ID:goolygu,项目名称:ros-deep-vision,代码行数:60,代码来源:image_misc.py
示例6: conv_backward_naive
def conv_backward_naive(dout, cache):
"""
A naive implementation of the backward pass for a convolutional layer.
Inputs:
- dout: Upstream derivatives.
- cache: A tuple of (x, w, b, conv_param) as in conv_forward_naive
Returns a tuple of:
- dx: Gradient with respect to x
- dw: Gradient with respect to w
- db: Gradient with respect to b
"""
# Setting up
x, w, b, conv_param = cache
dx = np.zeros_like(x)
dw = np.zeros_like(w)
db = np.zeros_like(b)
stride = conv_param['stride']
pad = conv_param['pad']
N, C, H, W = x.shape
F, _, HH, WW = w.shape
h_out = 1 + (H + 2 * pad - HH) / stride
w_out = 1 + (W + 2 * pad - WW) / stride
#############################################################################
# TODO: Implement the convolutional backward pass. #
#############################################################################
# Padding x and dx
x_padded = np.pad(x, [(0, 0), (0, 0), (pad, pad), (pad, pad)], mode='constant')
dx_padded = np.pad(dx, [(0, 0), (0, 0), (pad, pad), (pad, pad)], mode='constant')
# Do the convolutions
# For every image, pass it through the filter and update the output
for image in range(N):
for filter in range(F):
# Then, do the convolutions in over H and W
for height in xrange(h_out):
end_point_height = height * stride
for width in xrange(w_out):
end_point_width = width * stride
# Make the convolution window
conv_window = x_padded[image, :, end_point_height:end_point_height + HH,
end_point_width:end_point_width + WW]
# And update the derivatives
db[filter] += dout[image, filter, height, width]
dw[filter] += conv_window * dout[image, filter, height, width]
# Update DX at the convolution window
dx_padded[image, :, end_point_height:end_point_height + HH, end_point_width:end_point_width + WW] += \
w[filter] * \
dout[image, filter, height, width]
# And remove the padding
dx = dx_padded[:, :, pad:pad + H, pad:pad + W]
#############################################################################
# END OF YOUR CODE #
#############################################################################
return dx, dw, db
开发者ID:alexchao56,项目名称:cs231n,代码行数:60,代码来源:layers.py
示例7: deepflow2
def deepflow2( im1=None, im2=None, match=None, options=""):
"""
flow = deepflow2.deepflow2(image1, image2, match=None, options='')
Compute the flow between two images, eventually using given matches.
Images must be HxWx3 numpy arrays (convert to float32).
Match is an optional numpy array argument (None by default, ie no input match), where each row starts by x1 y1 x2 y2.
Options is an optional string argument ('' by default), to set the options. Type deepflow2() to see the list of available options.
The function returns the optical flow as a HxWx2 numpy array."""
#convert images
if None in (im1,im2):
usage_python()
return
assert im1.shape == im2.shape, "images must have the same shape"
if im1.dtype != float32:
im1 = im1.astype(float32)
if im2.dtype != float32:
im2 = im2.astype(float32)
h, w, nchannels = im1.shape
assert nchannels==3, "images must have 3 channels"
stride = 4*((w+3)//4)
im1 = pad( rollaxis(im1,2), ((0,0),(0,0),(0, stride-w)), 'constant')
im2 = pad( rollaxis(im2,2), ((0,0),(0,0),(0, stride-w)), 'constant')
# allocate flow
flowx = empty((h,stride), dtype=float32)
flowy = empty((h,stride), dtype=float32)
# compute flow
if match is not None:
assert match.shape[1]>=4
match = ascontiguousarray(match[:,:4], dtype=float32)
deepflow2_numpy( w, flowx, flowy, im1, im2, match, options)
return concatenate ( (flowx[:,:w,None], flowy[:,:w,None]), axis=2)
开发者ID:CansenJIANG,项目名称:deepFlowTrk,代码行数:31,代码来源:deepflow2.py
示例8: local_pad
def local_pad(x): # TODO replace with pad global function
if nf <= 1:
return x
if self._margin:
ma = self._margin
ba = (nf - 1) / 2 # before/after
if x.shape[0] - 2*ma <= 0:
print "shape[0]:", x.shape[0]
print "ma:", ma
if x.shape[1] * nf <= 0:
print "shape[1]:", x.shape[1]
print "nf:", nf
ret = numpy.zeros((x.shape[0] - 2 * ma, x.shape[1] * nf),
dtype=theano.config.floatX)
if ba <= ma:
for j in xrange(ret.shape[0]):
ret[j] = x[j:j + 2*ma + 1].flatten()
else:
for j in xrange(ret.shape[0]):
ret[j] = numpy.pad(x[max(0, j - ba):j + ba +1].flatten(),
(max(0, (ba - j) * x.shape[1]),
max(0, ((j + ba + 1) - x.shape[0]) * x.shape[1])),
'constant', constant_values=(0, 0))
return ret
else:
ret = numpy.zeros((x.shape[0], x.shape[1] * nf),
dtype=theano.config.floatX)
ba = (nf - 1) / 2 # before/after
for j in xrange(x.shape[0]):
ret[j] = numpy.pad(x[max(0, j - ba):j + ba +1].flatten(),
(max(0, (ba - j) * x.shape[1]),
max(0, ((j + ba + 1) - x.shape[0]) * x.shape[1])),
'constant', constant_values=(0, 0))
return ret
开发者ID:RolT,项目名称:timit_tools,代码行数:34,代码来源:dataset_iterators.py
示例9: _fixOddKernel
def _fixOddKernel(kernel):
"""Take a kernel with odd dimensions and make them even for FFT
Parameters
----------
kernel : `numpy.array`
a numpy.array
Returns
-------
out : `numpy.array`
a fixed kernel numpy.array. Returns a copy if the dimensions needed to change;
otherwise just return the input kernel.
"""
# Note this works best for the FFT if we left-pad
out = kernel
changed = False
if (out.shape[0] % 2) == 1:
out = np.pad(out, ((1, 0), (0, 0)), mode='constant')
changed = True
if (out.shape[1] % 2) == 1:
out = np.pad(out, ((0, 0), (1, 0)), mode='constant')
changed = True
if changed:
out *= (np.mean(kernel) / np.mean(out)) # need to re-scale to same mean for FFT
return out
开发者ID:HyperSuprime-Cam,项目名称:ip_diffim,代码行数:26,代码来源:imageDecorrelation.py
示例10: treatArray
def treatArray(data):
if border_mode == 'keep':
return data
if n_dim == 3:
sh = (data.shape[0], ) + data.shape[2:] # exclude channel (z,x,y)
else:
sh = data.shape[2:] # (x,y)
if border_mode == 'crop':
excess = map(lambda x: int((x[0] - x[1]) // 2), zip(sh, ps))
if n_dim == 3:
data = data[excess[0]:excess[0] + ps[0], :, excess[1]:excess[1] + ps[1], excess[2]:excess[2] + ps[2]]
elif n_dim == 2:
data = data[:, :, excess[0]:excess[0] + ps[0], excess[1]: excess[1] + ps[1]]
else:
excess_l = map(lambda x: int(np.ceil(float(x[0] - x[1]) / 2)), zip(ps, sh))
excess_r = map(lambda x: int(np.floor(float(x[0] - x[1]) / 2)), zip(ps, sh))
if n_dim == 3:
pad_with = [(excess_l[0], excess_r[0]), (0, 0), (excess_l[1], excess_r[1]), (excess_l[2], excess_r[2])]
else:
pad_with = [(0, 0), (0, 0), (excess_l[0], excess_r[0]), (excess_l[1], excess_r[1])]
if border_mode == 'mirror':
data = np.pad(data, pad_with, mode='symmetric')
if border_mode == '0-pad':
data = np.pad(data, pad_with, mode='constant', constant_values=0)
return data
开发者ID:ELEKTRONN,项目名称:ELEKTRONN,代码行数:31,代码来源:CNNData.py
示例11: test_find_center_vo_with_downsampling
def test_find_center_vo_with_downsampling(self):
sim = read_file('sinogram.npy')
np.pad(
sim, ((1000, 1000), (0, 0), (1000, 1000)),
mode="constant", constant_values=0)
cen = find_center_vo(sim)
assert_allclose(cen, 45.28, rtol=0.015)
开发者ID:decarlof,项目名称:tomopy,代码行数:7,代码来源:test_rotation.py
示例12: __init__
def __init__(self, G_list, max_num_nodes, features='id'):
self.max_num_nodes = max_num_nodes
self.adj_all = []
self.len_all = []
self.feature_all = []
for G in G_list:
adj = nx.to_numpy_matrix(G)
# the diagonal entries are 1 since they denote node probability
self.adj_all.append(
np.asarray(adj) + np.identity(G.number_of_nodes()))
self.len_all.append(G.number_of_nodes())
if features == 'id':
self.feature_all.append(np.identity(max_num_nodes))
elif features == 'deg':
degs = np.sum(np.array(adj), 1)
degs = np.expand_dims(np.pad(degs, [0, max_num_nodes - G.number_of_nodes()], 0),
axis=1)
self.feature_all.append(degs)
elif features == 'struct':
degs = np.sum(np.array(adj), 1)
degs = np.expand_dims(np.pad(degs, [0, max_num_nodes - G.number_of_nodes()],
'constant'),
axis=1)
clusterings = np.array(list(nx.clustering(G).values()))
clusterings = np.expand_dims(np.pad(clusterings,
[0, max_num_nodes - G.number_of_nodes()],
'constant'),
axis=1)
self.feature_all.append(np.hstack([degs, clusterings]))
开发者ID:taeyen,项目名称:graph-generation,代码行数:30,代码来源:data.py
示例13: calcgrad
def calcgrad(i):
#i=cv2.imread("images.png",0)
#i=[[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]]
#i=np.array(i)
height,width=i.shape
first=np.pad(i,((0,0),(1,0)),'constant')
second=np.pad(i,((0,1),(1,0)),'constant')
third=np.pad(i,((0,1),(0,0)),'constant')
fourth=np.pad(i,((0,1),(0,1)),'constant')
first=first[:,0:width]
second=second[1:height+1,0:width]
third=third[1:height+1,:]
fourth=fourth[1:height+1,1:width+1]
first=i-first
second=i-second
third=i-third
fourth=i-fourth
combo1=32*np.array( first >= second, dtype=int)
combo2=16*np.array( first >= third, dtype=int)
combo3=8*np.array( first >= fourth, dtype=int)
combo4=4*np.array( second >= third, dtype=int)
combo5=2*np.array( second >= fourth, dtype=int)
combo6=np.array( third >= fourth, dtype=int)
ldgp=combo1+combo2+combo3+combo4+combo5+combo6
return ldgp
开发者ID:gautamits,项目名称:Fisher,代码行数:28,代码来源:client.py
示例14: cross_correlation
def cross_correlation(x, y, maxlag):
"""
Cross correlation with a maximum number of lags.
`x` and `y` must be one-dimensional numpy arrays with the same length.
This computes the same result as
numpy.correlate(x, y, mode='full')[len(a)-maxlag-1:len(a)+maxlag]
The return vaue has length 2*maxlag + 1.
Author: http://stackoverflow.com/questions/30677241
Warren Weckesser
"""
from numpy.lib.stride_tricks import as_strided
def _check_arg(x, xname):
x = np.asarray(x)
if x.ndim != 1:
raise ValueError('%s must be one-dimensional.' % xname)
return x
x = _check_arg(x, 'x')
y = _check_arg(y, 'y')
py = np.pad(y.conj(), 2*maxlag, mode='constant')
T = as_strided(py[2*maxlag:], shape=(2*maxlag+1, len(y) + 2*maxlag),
strides=(-py.strides[0], py.strides[0]))
px = np.pad(x, maxlag, mode='constant')
return T.dot(px)
开发者ID:droidroot1995,项目名称:jr-tools,代码行数:29,代码来源:base.py
示例15: zero_padding
def zero_padding():
samples = 77
rec_period = 4
sampling_rate = samples/rec_period
time = np.linspace(0, rec_period, samples)
sin = np.sin(time*3.75*np.pi)
win = np.hanning(len(sin))
pad_count = 23
padded_sin = np.pad(sin, (0,pad_count), 'constant')
fft = np.fft.rfft(sin)
fft_padded = np.fft.rfft(padded_sin)
bins = (np.fft.rfftfreq(len(sin))*sampling_rate)[1:]
plt.subplot(321)
plt.plot(time, sin)
plt.subplot(322)
plt.plot(bins, (np.abs(fft))[1:]*2/samples, "o")
plt.subplot(323)
plt.plot(np.linspace(0, (samples+pad_count)*rec_period/float(samples), samples+pad_count), padded_sin)
plt.subplot(324)
plt.plot((np.fft.rfftfreq(len(padded_sin))*sampling_rate)[1:], (np.abs(fft_padded))[1:]*2/samples, "o")
plt.subplot(325)
padded_sin_win = np.pad(sin*win, (0, pad_count), 'constant')
plt.plot(np.linspace(0, (samples+pad_count)*rec_period/float(samples), samples+pad_count), padded_sin_win)
plt.subplot(326)
plt.plot((np.fft.rfftfreq(len(padded_sin_win))*sampling_rate)[1:], np.abs(np.fft.rfft(padded_sin_win))[1:]*2/samples, "o")
matplotlib2tikz.save( 'myfile.tikz' )
plt.show()
开发者ID:kahvel,项目名称:VEP-BCI-OLD,代码行数:30,代码来源:plot_generator.py
示例16: saveSlidingWindows
def saveSlidingWindows((im_path,filter_size,step_size,out_file_pre,idx)):
print idx;
im=scipy.misc.imread(im_path);
pad_r=getPadTuple(im.shape[0],filter_size[0],step_size);
pad_c=getPadTuple(im.shape[1],filter_size[1],step_size);
if len(im.shape)>2:
im=np.pad(im,(pad_r,pad_c,(0,0)),'edge')
else:
im=np.pad(im,(pad_r,pad_c),'edge');
start_r=0;
idx_r=0;
out_files=[];
while start_r<im.shape[0]:
start_c=0;
idx_c=0;
while start_c<im.shape[1]:
end_r=start_r+filter_size[0];
end_c=start_c+filter_size[1];
crop_curr=im[start_r:end_r,start_c:end_c];
out_file_curr=out_file_pre+'_'+str(idx_r)+'_'+str(idx_c)+'.png';
scipy.misc.imsave(out_file_curr,crop_curr);
out_files.append(out_file_curr);
start_c=start_c+step_size;
idx_c+=1;
start_r=start_r+step_size;
idx_r+=1;
return out_files;
开发者ID:maheenRashid,项目名称:dense_opt_scripts,代码行数:33,代码来源:processOutput.py
示例17: _zero_pad_to_same_size
def _zero_pad_to_same_size(a, b):
[ay, ax], [by, bx] = a.shape, b.shape
if ax < bx or ay < by:
a = np.pad(a, ( (by-ay,0),(bx-ax,0) ), mode='constant')
elif ax > bx or ay > by:
b = np.pad(b, ( (ay-by,0),(ax-bx,0) ), mode='constant')
return a, b, [ax-bx, ay-by]
开发者ID:sargas,项目名称:dct,代码行数:7,代码来源:lmi.py
示例18: __init__
def __init__(self,h5_path,image_paths,max_q=None,max_mc=None):
self.h5 = h5py.File(h5_path,mode='r')
self.image_ids = self.h5['image_ids'].value
self.questions = self.h5['questions'].value
self.multiple_choice = self.h5['multiple_choices'].value
self.answers = self.h5['ground_truth'].value
self.N = len(self.image_ids)
if max_q:
if max_q<self.questions.shape[1]:
self.questions = self.questions[:,:max_q]
else:
self.questions = np.pad(self.questions,
((0,0),(0,max_q-self.questions.shape[-1])),
'constant',constant_values=w2i['</s>'])
if max_mc:
if max_mc<self.multiple_choice.shape[-1]:
self.multiple_choice = self.multiple_choice[:,:,max_mc]
else:
self.multiple_choice = np.pad(self.multiple_choice,
((0,0),(0,0),(0,max_mc-self.multiple_choice.shape[-1])),
'constant',constant_values=w2i['</s>'])
self.max_mc = self.multiple_choice.shape[1]
self.max_q = self.questions.shape[1]
self.indexes = np.arange(self.N)
self.image_paths = image_paths
开发者ID:Hediby,项目名称:vanilla_vqa,代码行数:25,代码来源:vqa_newloss_wholeimage.py
示例19: qea
def qea(im):
H = ss.hilbert(im,axis = 2)
H = im+1j*H
ia = np.abs(H)
ip = np.angle(H)
h1col = H[1:-1,:,:]
h0col = H[:-2,:,:]
h2col = H[2:,:,:]
ifColSign = np.sign(np.real((h0col-h2col)/(2j*h1col)))
ifCol = np.arccos((h2col+h0col)/(2*h1col))
ifCol = (np.abs(ifCol)*ifColSign)/np.pi/2
ifCol = np.pad(ifCol,((1,1),(0,0),(0,0)), mode='reflect')
h0row = H[:,:-2,:]
h1row = H[:,1:-1,:]
h2row = H[:,2:,:]
#ifxSign = np.sign(np.real((h2x-h0x)/(2j*h1x)))
ifRow = np.arccos((h2row+h0row)/(2*h1row))
ifRow = (np.abs(ifRow))/np.pi/2
ifRow = np.pad(ifRow,((0,0),(1,1),(0,0)), mode='reflect')
h0time = H[:,:,:-2]
h1time = H[:,:,1:-1]
h2time = H[:,:,2:]
#ifxSign = np.sign(np.real((h2x-h0x)/(2j*h1x)))
ifTime = np.arccos((h2time+h0time)/(2*h1time))
ifTime = (np.abs(ifTime))/np.pi/2
ifTime = np.pad(ifTime,((0,0),(0,0),(1,1)), mode='reflect')
return(ia,ip,ifRow,ifCol,ifTime)
开发者ID:alvarouc,项目名称:amfm,代码行数:34,代码来源:amfm3d.py
示例20: __init__
def __init__(self,h5_path,image_paths,max_q=None,max_mc=None):
self.h5 = h5py.File(h5_path,mode='r')
self.image_ids = self.h5['image_ids'].value
self.questions = self.h5['questions'].value
self.multiple_choice = self.h5['multiple_choice'].value
self.answers = self.h5['answers'].value
self.bounding_boxes = dict((k,v) for (k,v) in zip(self.h5['img_list'].value,
self.h5['bounding_boxes'].value))
self.N = len(self.image_ids)
if max_q:
if max_q<self.questions.shape[1]:
self.questions = self.questions[:,:max_q]
else:
self.questions = np.pad(self.questions,
((0,0),(0,max_q-self.questions.shape[-1])),
'constant',constant_values=a_w2i['</s>'])
if max_mc:
if max_mc<self.multiple_choice.shape[-1]:
self.multiple_choice = self.multiple_choice[:,:,max_mc]
else:
self.multiple_choice = np.pad(self.multiple_choice,
((0,0),(0,0),(0,max_mc-self.multiple_choice.shape[-1])),
'constant',constant_values=a_w2i['</s>'])
self.max_q = self.questions.shape[1]
self.indexes = np.arange(self.N)
self.image_paths = image_paths
开发者ID:Hediby,项目名称:vanilla_vqa,代码行数:26,代码来源:simple_pooling.py
注:本文中的numpy.pad函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论