Python scipy.misc 模块,imrotate() 实例源码
我们从Python开源项目中,提取了以下20个代码示例,用于说明如何使用scipy.misc.imrotate()。
def run_pretrained(input_state,model,action_states,gameState):
print '\n\nLoading pretrained weights onto model...'
model.load_weights(p.PRETRAINED_PATH)
epsilon=1
while True:
print 'Running pretrained model (no exploration) with weights at ', p.PRETRAINED_PATH
nn_out = model.predict(input_state,batch_size=1,verbose=0)
nn_action = [[0,0]]
nn_action[0][np.argmax(nn_out)] =1
action,rand_flag = select_action(nn_action+action_states,prob=[epsilon,(1-epsilon)*1/7,(1-epsilon)*6/7])
rgbdisplay, reward, tState = gameState.frame_step(action)
graydisplay = (np.dot(np.fliplr(imrotate(imresize(rgbdisplay, (80,80), interp='bilinear'), -90))[:,:,:3], [0.299, 0.587, 0.114])).reshape((1,1,80,80))
output_state = np.append(graydisplay,input_state[:,:p.HISTORY-1,:], axis=1)
#############################################################################################################################################################################
def read_images_from_disk(input_queue):
"""Consumes a single filename and label as a ' '-delimited string.
Args:
filename_and_label_tensor: A scalar string tensor.
Returns:
Two tensors: the decoded image,and the string label.
"""
label = input_queue[1]
file_contents = tf.read_file(input_queue[0])
example = tf.image.decode_png(file_contents, channels=3)
return example, label
# def random_rotate_image(image):
# angle = np.random.uniform(low=-10.0,high=10.0)
# return misc.imrotate(image,angle,'bicubic')
def crawl_directory(directory, augment_with_rotations=False, first_label=0):
"""Crawls data directory and returns stuff."""
label_idx = first_label
images = []
labels = []
info = []
# traverse root directory
for root, _, files in os.walk(directory):
logging.info('Reading files from %s', root)
for file_name in files:
full_file_name = os.path.join(root, file_name)
img = imread(full_file_name, flatten=True)
for idx, angle in enumerate([0, 90, 180, 270]):
if not augment_with_rotations and idx > 0:
break
images.append(imrotate(img, angle))
labels.append(label_idx + idx)
info.append(full_file_name)
if len(files) == 20:
label_idx += 4 if augment_with_rotations else 1
return images, labels, info
def _rotate_batch(batch, angle):
return np.vstack([rotate(x_i.reshape(28, 28), angle).reshape([-1, 28*28])
for x_i in batch])
def random_rotate_image(image):
angle = np.random.uniform(low=-10.0, high=10.0)
return misc.imrotate(image, angle, 'bicubic')
def random_rotate_image(image):
# rotate image for data augmentation
angle = np.random.uniform(low=-20.0, high=20.0)
return misc.imrotate(image, 'bicubic')
def plotCluster( _x, core_samples_mask, n_clusters_, f):
unique_labels = set(labels)
colors = plt.cm.Spectral(np.linspace(0, 1, len(unique_labels)))
for k, col in zip(unique_labels, colors):
if k == -1:
# Black used for noise.
col = 'k'
class_member_mask = (labels == k)
xy = _x[class_member_mask & ~core_samples_mask]
ax = plt.plot(xy[:, 0], xy[:, 1], 'o', markerfacecolor=col,
markeredgecolor='k', markersize=6)
xy = _x[class_member_mask & core_samples_mask]
ax = plt.plot(xy[:, markersize=14)
#plt.title('Estimated number of clusters: %d' % n_clusters_)
#plt.axis('off')
#misc.imrotate(ax,270)
index = f
print f
plt.axis('off')
plt.savefig(f)
image_rotate(f)
plt.close()
#plt.show()
return
def random_rotate_image(image):
angle = np.random.uniform(low=-10.0, 'bicubic')
def rotate_images(images, image_size):
images_list = [None] * images.shape[0]
for i in range(images.shape[0]):
images_list[i] = misc.imrotate(images[i, angle)
images_rot = np.stack(images_list,axis=0)
sz1 = images_rot.shape[1]/2
sz2 = image_size/2
images_crop = images_rot[:,(sz1-sz2):(sz1+sz2),:]
return images_crop
def random_rotate_image(image):
angle = np.random.uniform(low=-10.0, 'bicubic')
def run_pretrained(input_state,gameState):
print '\n\nLoading pretrained weights onto model...'
model.load_weights(p.PRETRAINED_PATH)
epsilon=1
while True:
print 'Running pretrained model (no exploration) with weights at ',1]] if np.argmax(nn_out) else [[1,0]]
action,(1-epsilon)/2,(1-epsilon)/2])
rgbdisplay, tState = gameState.frame_step(action)
#graydisplay = (np.dot(imresize(rgbdisplay,(80,80),interp='bilinear')[:,:3],[0.299,0.587,0.114])).reshape((1,1,80,80))
graydisplay = (np.dot(np.fliplr(imrotate(imresize(rgbdisplay,80))
output_state = np.append(input_state[:,1:, graydisplay,axis=1)
#############################################################################################################################################################################
def rotate_frame(frame, angle):
# Perform the image rotation and update the fits header
#frame[np.isnan(frame)] = 0.0
new_frame = ndimage.interpolation.rotate(frame, reshape=False, order=1, mode='constant', cval=float('nan'))
#new_frame = misc.imrotate(frame,interp="bilinear")
# Return the rotated frame
return new_frame
def rotate_frame(frame,interp="bilinear")
# Return the rotated frame
return new_frame
def random_rotate_image(image):
angle = np.random.uniform(low=-10.0, 'bicubic')
def random_rotate_image(image):
angle = np.random.uniform(low=-10.0, 'bicubic')
def random_rotate_image(image):
angle = np.random.uniform(low=-10.0, 'bicubic')
def _rotate_batch(batch, 28*28])
for x_i in batch]) / 255.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。