本文整理汇总了Python中scipy.misc.face方法的典型用法代码示例。如果您正苦于以下问题:Python misc.face方法的具体用法?Python misc.face怎么用?Python misc.face使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scipy.misc
的用法示例。
在下文中一共展示了misc.face方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_extract_patches_max_patches
# 需要导入模块: from scipy import misc [as 别名]
# 或者: from scipy.misc import face [as 别名]
def test_extract_patches_max_patches():
face = downsampled_face
i_h, i_w = face.shape
p_h, p_w = 16, 16
patches = extract_patches_2d(face, (p_h, p_w), max_patches=100)
assert_equal(patches.shape, (100, p_h, p_w))
expected_n_patches = int(0.5 * (i_h - p_h + 1) * (i_w - p_w + 1))
patches = extract_patches_2d(face, (p_h, p_w), max_patches=0.5)
assert_equal(patches.shape, (expected_n_patches, p_h, p_w))
assert_raises(ValueError, extract_patches_2d, face, (p_h, p_w),
max_patches=2.0)
assert_raises(ValueError, extract_patches_2d, face, (p_h, p_w),
max_patches=-1.0)
示例2: parse_args
# 需要导入模块: from scipy import misc [as 别名]
# 或者: from scipy.misc import face [as 别名]
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument('--cuda', action='store_true', default=False,
help='Use NVIDIA GPU acceleration')
parser.add_argument('--img', type=str, default='',
help='Input image path')
parser.add_argument('--out_dir', type=str, default='./result/cam/',
help='Result directory path')
args = parser.parse_args()
args.cuda = args.cuda and torch.cuda.is_available()
if args.cuda:
print("Using GPU for acceleration")
else:
print("Using CPU for computation")
if args.img:
print('Input image: {}'.format(args.img))
else:
print('Input image: raccoon face (scipy.misc.face())')
print('Output directory: {}'.format(args.out_dir))
print()
return args
示例3: parse_args
# 需要导入模块: from scipy import misc [as 别名]
# 或者: from scipy.misc import face [as 别名]
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument('--cuda', action='store_true', default=False,
help='Use NVIDIA GPU acceleration')
parser.add_argument('--img', type=str, default='',
help='Input image path')
parser.add_argument('--out_dir', type=str, default='./result/grad/',
help='Result directory path')
parser.add_argument('--n_samples', type=int, default=10,
help='Sample size of SmoothGrad')
args = parser.parse_args()
args.cuda = args.cuda and torch.cuda.is_available()
if args.cuda:
print("Using GPU for acceleration")
else:
print("Using CPU for computation")
if args.img:
print('Input image: {}'.format(args.img))
else:
print('Input image: raccoon face (scipy.misc.face())')
print('Output directory: {}'.format(args.out_dir))
print('Sample size of SmoothGrad: {}'.format(args.n_samples))
print()
return args
示例4: setUp
# 需要导入模块: from scipy import misc [as 别名]
# 或者: from scipy.misc import face [as 别名]
def setUp(self):
super(TestImageLoader, self).setUp()
from PIL import Image
self.current_dir = os.path.dirname(os.path.abspath(__file__))
self.tif_image_path = os.path.join(self.current_dir, "a_image.tif")
# Create image file
self.data_dir = tempfile.mkdtemp()
self.face = misc.face()
self.face_path = os.path.join(self.data_dir, "face.png")
Image.fromarray(self.face).save(self.face_path)
self.face_copy_path = os.path.join(self.data_dir, "face_copy.png")
Image.fromarray(self.face).save(self.face_copy_path)
# Create zip of image file
#self.zip_path = "/home/rbharath/misc/cells.zip"
self.zip_path = os.path.join(self.data_dir, "face.zip")
zipf = zipfile.ZipFile(self.zip_path, "w", zipfile.ZIP_DEFLATED)
zipf.write(self.face_path)
zipf.close()
# Create zip of multiple image files
self.multi_zip_path = os.path.join(self.data_dir, "multi_face.zip")
zipf = zipfile.ZipFile(self.multi_zip_path, "w", zipfile.ZIP_DEFLATED)
zipf.write(self.face_path)
zipf.write(self.face_copy_path)
zipf.close()
# Create zip of multiple image files, multiple_types
self.multitype_zip_path = os.path.join(self.data_dir, "multitype_face.zip")
zipf = zipfile.ZipFile(self.multitype_zip_path, "w", zipfile.ZIP_DEFLATED)
zipf.write(self.face_path)
zipf.write(self.tif_image_path)
zipf.close()
# Create image directory
self.image_dir = tempfile.mkdtemp()
face_path = os.path.join(self.image_dir, "face.png")
Image.fromarray(self.face).save(face_path)
face_copy_path = os.path.join(self.image_dir, "face_copy.png")
Image.fromarray(self.face).save(face_copy_path)
示例5: test_png_simple_load
# 需要导入模块: from scipy import misc [as 别名]
# 或者: from scipy.misc import face [as 别名]
def test_png_simple_load(self):
loader = dc.data.ImageLoader()
dataset = loader.featurize(self.face_path)
# These are the known dimensions of face.png
assert dataset.X.shape == (1, 768, 1024, 3)
示例6: test_face
# 需要导入模块: from scipy import misc [as 别名]
# 或者: from scipy.misc import face [as 别名]
def test_face():
assert_equal(face().shape, (768, 1024, 3))
示例7: test_connect_regions
# 需要导入模块: from scipy import misc [as 别名]
# 或者: from scipy.misc import face [as 别名]
def test_connect_regions():
try:
face = sp.face(gray=True)
except AttributeError:
# Newer versions of scipy have face in misc
from scipy import misc
face = misc.face(gray=True)
for thr in (50, 150):
mask = face > thr
graph = img_to_graph(face, mask)
assert_equal(ndimage.label(mask)[1], connected_components(graph)[0])
示例8: test_connect_regions_with_grid
# 需要导入模块: from scipy import misc [as 别名]
# 或者: from scipy.misc import face [as 别名]
def test_connect_regions_with_grid():
try:
face = sp.face(gray=True)
except AttributeError:
# Newer versions of scipy have face in misc
from scipy import misc
face = misc.face(gray=True)
mask = face > 50
graph = grid_to_graph(*face.shape, mask=mask)
assert_equal(ndimage.label(mask)[1], connected_components(graph)[0])
mask = face > 150
graph = grid_to_graph(*face.shape, mask=mask, dtype=None)
assert_equal(ndimage.label(mask)[1], connected_components(graph)[0])
示例9: _downsampled_face
# 需要导入模块: from scipy import misc [as 别名]
# 或者: from scipy.misc import face [as 别名]
def _downsampled_face():
try:
face = sp.face(gray=True)
except AttributeError:
# Newer versions of scipy have face in misc
from scipy import misc
face = misc.face(gray=True)
face = face.astype(np.float32)
face = (face[::2, ::2] + face[1::2, ::2] + face[::2, 1::2]
+ face[1::2, 1::2])
face = (face[::2, ::2] + face[1::2, ::2] + face[::2, 1::2]
+ face[1::2, 1::2])
face = face.astype(np.float32)
face /= 16.0
return face
示例10: _orange_face
# 需要导入模块: from scipy import misc [as 别名]
# 或者: from scipy.misc import face [as 别名]
def _orange_face(face=None):
face = _downsampled_face() if face is None else face
face_color = np.zeros(face.shape + (3,))
face_color[:, :, 0] = 256 - face
face_color[:, :, 1] = 256 - face / 2
face_color[:, :, 2] = 256 - face / 4
return face_color
示例11: _make_images
# 需要导入模块: from scipy import misc [as 别名]
# 或者: from scipy.misc import face [as 别名]
def _make_images(face=None):
face = _downsampled_face() if face is None else face
# make a collection of faces
images = np.zeros((3,) + face.shape)
images[0] = face
images[1] = face + 1
images[2] = face + 2
return images
示例12: test_extract_patches_all_color
# 需要导入模块: from scipy import misc [as 别名]
# 或者: from scipy.misc import face [as 别名]
def test_extract_patches_all_color():
face = orange_face
i_h, i_w = face.shape[:2]
p_h, p_w = 16, 16
expected_n_patches = (i_h - p_h + 1) * (i_w - p_w + 1)
patches = extract_patches_2d(face, (p_h, p_w))
assert_equal(patches.shape, (expected_n_patches, p_h, p_w, 3))
示例13: test_extract_patches_all_rect
# 需要导入模块: from scipy import misc [as 别名]
# 或者: from scipy.misc import face [as 别名]
def test_extract_patches_all_rect():
face = downsampled_face
face = face[:, 32:97]
i_h, i_w = face.shape
p_h, p_w = 16, 12
expected_n_patches = (i_h - p_h + 1) * (i_w - p_w + 1)
patches = extract_patches_2d(face, (p_h, p_w))
assert_equal(patches.shape, (expected_n_patches, p_h, p_w))
示例14: test_extract_patch_same_size_image
# 需要导入模块: from scipy import misc [as 别名]
# 或者: from scipy.misc import face [as 别名]
def test_extract_patch_same_size_image():
face = downsampled_face
# Request patches of the same size as image
# Should return just the single patch a.k.a. the image
patches = extract_patches_2d(face, face.shape, max_patches=2)
assert_equal(patches.shape[0], 1)
示例15: test_extract_patches_less_than_max_patches
# 需要导入模块: from scipy import misc [as 别名]
# 或者: from scipy.misc import face [as 别名]
def test_extract_patches_less_than_max_patches():
face = downsampled_face
i_h, i_w = face.shape
p_h, p_w = 3 * i_h // 4, 3 * i_w // 4
# this is 3185
expected_n_patches = (i_h - p_h + 1) * (i_w - p_w + 1)
patches = extract_patches_2d(face, (p_h, p_w), max_patches=4000)
assert_equal(patches.shape, (expected_n_patches, p_h, p_w))