Merge 59466e3068 into ae05379cc9
This commit is contained in:
commit
3fffb37c03
|
|
@ -6,7 +6,7 @@ from PIL import Image
|
|||
from extras.inpaint_mask import SAMOptions, generate_mask_from_image
|
||||
|
||||
original_image = Image.open('cat.webp')
|
||||
image = np.array(original_image, dtype=np.uint8)
|
||||
image = np.asarray(original_image, dtype=np.uint8)
|
||||
|
||||
sam_options = SAMOptions(
|
||||
dino_prompt='eye',
|
||||
|
|
|
|||
|
|
@ -49,12 +49,12 @@ def get_reference_facial_points(output_size=None, inner_padding_factor=0.0, oute
|
|||
inner_padding_factor))
|
||||
Returns:
|
||||
----------
|
||||
@reference_5point: 5x2 np.array
|
||||
@reference_5point: 5x2 np.asarray
|
||||
each row is a pair of transformed coordinates (x, y)
|
||||
"""
|
||||
|
||||
tmp_5pts = np.array(REFERENCE_FACIAL_POINTS)
|
||||
tmp_crop_size = np.array(DEFAULT_CROP_SIZE)
|
||||
tmp_5pts = np.asarray(REFERENCE_FACIAL_POINTS)
|
||||
tmp_crop_size = np.asarray(DEFAULT_CROP_SIZE)
|
||||
|
||||
# 0) make the inner region a square
|
||||
if default_square:
|
||||
|
|
@ -79,7 +79,7 @@ def get_reference_facial_points(output_size=None, inner_padding_factor=0.0, oute
|
|||
if ((inner_padding_factor > 0 or outer_padding[0] > 0 or outer_padding[1] > 0) and output_size is None):
|
||||
output_size = tmp_crop_size * \
|
||||
(1 + inner_padding_factor * 2).astype(np.int32)
|
||||
output_size += np.array(outer_padding)
|
||||
output_size += np.asarray(outer_padding)
|
||||
if not (outer_padding[0] < output_size[0] and outer_padding[1] < output_size[1]):
|
||||
raise FaceWarpException('Not (outer_padding[0] < output_size[0] and outer_padding[1] < output_size[1])')
|
||||
|
||||
|
|
@ -90,7 +90,7 @@ def get_reference_facial_points(output_size=None, inner_padding_factor=0.0, oute
|
|||
tmp_crop_size += np.round(size_diff).astype(np.int32)
|
||||
|
||||
# 2) resize the padded inner region
|
||||
size_bf_outer_pad = np.array(output_size) - np.array(outer_padding) * 2
|
||||
size_bf_outer_pad = np.asarray(output_size) - np.asarray(outer_padding) * 2
|
||||
|
||||
if size_bf_outer_pad[0] * tmp_crop_size[1] != size_bf_outer_pad[1] * tmp_crop_size[0]:
|
||||
raise FaceWarpException('Must have (output_size - outer_padding)'
|
||||
|
|
@ -103,7 +103,7 @@ def get_reference_facial_points(output_size=None, inner_padding_factor=0.0, oute
|
|||
tmp_crop_size = size_bf_outer_pad
|
||||
|
||||
# 3) add outer_padding to make output_size
|
||||
reference_5point = tmp_5pts + np.array(outer_padding)
|
||||
reference_5point = tmp_5pts + np.asarray(outer_padding)
|
||||
tmp_crop_size = output_size
|
||||
|
||||
return reference_5point
|
||||
|
|
@ -116,13 +116,13 @@ def get_affine_transform_matrix(src_pts, dst_pts):
|
|||
get affine transform matrix 'tfm' from src_pts to dst_pts
|
||||
Parameters:
|
||||
----------
|
||||
@src_pts: Kx2 np.array
|
||||
@src_pts: Kx2 np.asarray
|
||||
source points matrix, each row is a pair of coordinates (x, y)
|
||||
@dst_pts: Kx2 np.array
|
||||
@dst_pts: Kx2 np.asarray
|
||||
destination points matrix, each row is a pair of coordinates (x, y)
|
||||
Returns:
|
||||
----------
|
||||
@tfm: 2x3 np.array
|
||||
@tfm: 2x3 np.asarray
|
||||
transform matrix from src_pts to dst_pts
|
||||
"""
|
||||
|
||||
|
|
@ -149,17 +149,17 @@ def warp_and_crop_face(src_img, facial_pts, reference_pts=None, crop_size=(96, 1
|
|||
apply affine transform 'trans' to uv
|
||||
Parameters:
|
||||
----------
|
||||
@src_img: 3x3 np.array
|
||||
@src_img: 3x3 np.asarray
|
||||
input image
|
||||
@facial_pts: could be
|
||||
1)a list of K coordinates (x,y)
|
||||
or
|
||||
2) Kx2 or 2xK np.array
|
||||
2) Kx2 or 2xK np.asarray
|
||||
each row or col is a pair of coordinates (x, y)
|
||||
@reference_pts: could be
|
||||
1) a list of K coordinates (x,y)
|
||||
or
|
||||
2) Kx2 or 2xK np.array
|
||||
2) Kx2 or 2xK np.asarray
|
||||
each row or col is a pair of coordinates (x, y)
|
||||
or
|
||||
3) None
|
||||
|
|
|
|||
|
|
@ -18,14 +18,14 @@ def tformfwd(trans, uv):
|
|||
|
||||
Parameters:
|
||||
----------
|
||||
@trans: 3x3 np.array
|
||||
@trans: 3x3 np.asarray
|
||||
transform matrix
|
||||
@uv: Kx2 np.array
|
||||
@uv: Kx2 np.asarray
|
||||
each row is a pair of coordinates (x, y)
|
||||
|
||||
Returns:
|
||||
----------
|
||||
@xy: Kx2 np.array
|
||||
@xy: Kx2 np.asarray
|
||||
each row is a pair of transformed coordinates (x, y)
|
||||
"""
|
||||
uv = np.hstack((uv, np.ones((uv.shape[0], 1))))
|
||||
|
|
@ -42,14 +42,14 @@ def tforminv(trans, uv):
|
|||
|
||||
Parameters:
|
||||
----------
|
||||
@trans: 3x3 np.array
|
||||
@trans: 3x3 np.asarray
|
||||
transform matrix
|
||||
@uv: Kx2 np.array
|
||||
@uv: Kx2 np.asarray
|
||||
each row is a pair of coordinates (x, y)
|
||||
|
||||
Returns:
|
||||
----------
|
||||
@xy: Kx2 np.array
|
||||
@xy: Kx2 np.asarray
|
||||
each row is a pair of inverse-transformed coordinates (x, y)
|
||||
"""
|
||||
Tinv = inv(trans)
|
||||
|
|
@ -84,9 +84,9 @@ def findNonreflectiveSimilarity(uv, xy, options=None):
|
|||
tx = r[2]
|
||||
ty = r[3]
|
||||
|
||||
Tinv = np.array([[sc, -ss, 0], [ss, sc, 0], [tx, ty, 1]])
|
||||
Tinv = np.asarray([[sc, -ss, 0], [ss, sc, 0], [tx, ty, 1]])
|
||||
T = inv(Tinv)
|
||||
T[:, 2] = np.array([0, 0, 1])
|
||||
T[:, 2] = np.asarray([0, 0, 1])
|
||||
|
||||
return T, Tinv
|
||||
|
||||
|
|
@ -94,8 +94,8 @@ def findNonreflectiveSimilarity(uv, xy, options=None):
|
|||
def findSimilarity(uv, xy, options=None):
|
||||
options = {'K': 2}
|
||||
|
||||
# uv = np.array(uv)
|
||||
# xy = np.array(xy)
|
||||
# uv = np.asarray(uv)
|
||||
# xy = np.asarray(xy)
|
||||
|
||||
# Solve for trans1
|
||||
trans1, trans1_inv = findNonreflectiveSimilarity(uv, xy, options)
|
||||
|
|
@ -109,7 +109,7 @@ def findSimilarity(uv, xy, options=None):
|
|||
trans2r, trans2r_inv = findNonreflectiveSimilarity(uv, xyR, options)
|
||||
|
||||
# manually reflect the tform to undo the reflection done on xyR
|
||||
TreflectY = np.array([[-1, 0, 0], [0, 1, 0], [0, 0, 1]])
|
||||
TreflectY = np.asarray([[-1, 0, 0], [0, 1, 0], [0, 0, 1]])
|
||||
|
||||
trans2 = np.dot(trans2r, TreflectY)
|
||||
|
||||
|
|
@ -140,9 +140,9 @@ def get_similarity_transform(src_pts, dst_pts, reflective=True):
|
|||
|
||||
Parameters:
|
||||
----------
|
||||
@src_pts: Kx2 np.array
|
||||
@src_pts: Kx2 np.asarray
|
||||
source points, each row is a pair of coordinates (x, y)
|
||||
@dst_pts: Kx2 np.array
|
||||
@dst_pts: Kx2 np.asarray
|
||||
destination points, each row is a pair of transformed
|
||||
coordinates (x, y)
|
||||
@reflective: True or False
|
||||
|
|
@ -153,9 +153,9 @@ def get_similarity_transform(src_pts, dst_pts, reflective=True):
|
|||
|
||||
Returns:
|
||||
----------
|
||||
@trans: 3x3 np.array
|
||||
@trans: 3x3 np.asarray
|
||||
transform matrix from uv to xy
|
||||
trans_inv: 3x3 np.array
|
||||
trans_inv: 3x3 np.asarray
|
||||
inverse of trans, transform matrix from xy to uv
|
||||
"""
|
||||
|
||||
|
|
@ -181,12 +181,12 @@ def cvt_tform_mat_for_cv2(trans):
|
|||
|
||||
Parameters:
|
||||
----------
|
||||
@trans: 3x3 np.array
|
||||
@trans: 3x3 np.asarray
|
||||
transform matrix from uv to xy
|
||||
|
||||
Returns:
|
||||
----------
|
||||
@cv2_trans: 2x3 np.array
|
||||
@cv2_trans: 2x3 np.asarray
|
||||
transform matrix from src_pts to dst_pts, could be directly used
|
||||
for cv2.warpAffine()
|
||||
"""
|
||||
|
|
@ -209,9 +209,9 @@ def get_similarity_transform_for_cv2(src_pts, dst_pts, reflective=True):
|
|||
|
||||
Parameters:
|
||||
----------
|
||||
@src_pts: Kx2 np.array
|
||||
@src_pts: Kx2 np.asarray
|
||||
source points, each row is a pair of coordinates (x, y)
|
||||
@dst_pts: Kx2 np.array
|
||||
@dst_pts: Kx2 np.asarray
|
||||
destination points, each row is a pair of transformed
|
||||
coordinates (x, y)
|
||||
reflective: True or False
|
||||
|
|
@ -222,7 +222,7 @@ def get_similarity_transform_for_cv2(src_pts, dst_pts, reflective=True):
|
|||
|
||||
Returns:
|
||||
----------
|
||||
@cv2_trans: 2x3 np.array
|
||||
@cv2_trans: 2x3 np.asarray
|
||||
transform matrix from src_pts to dst_pts, could be directly used
|
||||
for cv2.warpAffine()
|
||||
"""
|
||||
|
|
@ -276,8 +276,8 @@ if __name__ == '__main__':
|
|||
x = [-1, 0, 4]
|
||||
y = [-1, -10, 4]
|
||||
|
||||
uv = np.array((u, v)).T
|
||||
xy = np.array((x, y)).T
|
||||
uv = np.asarray((u, v)).T
|
||||
xy = np.asarray((x, y)).T
|
||||
|
||||
print('\n--->uv:')
|
||||
print(uv)
|
||||
|
|
|
|||
|
|
@ -245,7 +245,7 @@ class RetinaFace(nn.Module):
|
|||
for landmark in landmarks:
|
||||
facial5points = [[landmark[2 * j], landmark[2 * j + 1]] for j in range(5)]
|
||||
|
||||
warped_face = warp_and_crop_face(np.array(image), facial5points, self.reference, crop_size=(112, 112))
|
||||
warped_face = warp_and_crop_face(np.asarray(image), facial5points, self.reference, crop_size=(112, 112))
|
||||
faces.append(warped_face)
|
||||
|
||||
return np.concatenate((boxes, landmarks), axis=1), faces
|
||||
|
|
@ -304,15 +304,15 @@ class RetinaFace(nn.Module):
|
|||
def batched_detect_faces(self, frames, conf_threshold=0.8, nms_threshold=0.4, use_origin_size=True):
|
||||
"""
|
||||
Arguments:
|
||||
frames: a list of PIL.Image, or np.array(shape=[n, h, w, c],
|
||||
frames: a list of PIL.Image, or np.asarray(shape=[n, h, w, c],
|
||||
type=np.uint8, BGR format).
|
||||
conf_threshold: confidence threshold.
|
||||
nms_threshold: nms threshold.
|
||||
use_origin_size: whether to use origin size.
|
||||
Returns:
|
||||
final_bounding_boxes: list of np.array ([n_boxes, 5],
|
||||
final_bounding_boxes: list of np.asarray ([n_boxes, 5],
|
||||
type=np.float32).
|
||||
final_landmarks: list of np.array ([n_boxes, 10], type=np.float32).
|
||||
final_landmarks: list of np.asarray ([n_boxes, 10], type=np.float32).
|
||||
"""
|
||||
# self.t['forward_pass'].tic()
|
||||
frames, self.resize = self.batched_transform(frames, use_origin_size)
|
||||
|
|
@ -340,8 +340,8 @@ class RetinaFace(nn.Module):
|
|||
# ignore low scores
|
||||
pred, landm = pred[inds, :], landm[inds, :]
|
||||
if pred.shape[0] == 0:
|
||||
final_bounding_boxes.append(np.array([], dtype=np.float32))
|
||||
final_landmarks.append(np.array([], dtype=np.float32))
|
||||
final_bounding_boxes.append(np.asarray([], dtype=np.float32))
|
||||
final_landmarks.append(np.asarray([], dtype=np.float32))
|
||||
continue
|
||||
|
||||
# sort
|
||||
|
|
|
|||
|
|
@ -33,12 +33,12 @@ def get_largest_face(det_faces, h, w):
|
|||
|
||||
def get_center_face(det_faces, h=0, w=0, center=None):
|
||||
if center is not None:
|
||||
center = np.array(center)
|
||||
center = np.asarray(center)
|
||||
else:
|
||||
center = np.array([w / 2, h / 2])
|
||||
center = np.asarray([w / 2, h / 2])
|
||||
center_dist = []
|
||||
for det_face in det_faces:
|
||||
face_center = np.array([(det_face[0] + det_face[2]) / 2, (det_face[1] + det_face[3]) / 2])
|
||||
face_center = np.asarray([(det_face[0] + det_face[2]) / 2, (det_face[1] + det_face[3]) / 2])
|
||||
dist = np.linalg.norm(face_center - center)
|
||||
center_dist.append(dist)
|
||||
center_idx = center_dist.index(min(center_dist))
|
||||
|
|
@ -67,10 +67,10 @@ class FaceRestoreHelper(object):
|
|||
self.face_size = (int(face_size * self.crop_ratio[1]), int(face_size * self.crop_ratio[0]))
|
||||
|
||||
if self.template_3points:
|
||||
self.face_template = np.array([[192, 240], [319, 240], [257, 371]])
|
||||
self.face_template = np.asarray([[192, 240], [319, 240], [257, 371]])
|
||||
else:
|
||||
# standard 5 landmarks for FFHQ faces with 512 x 512
|
||||
self.face_template = np.array([[192.98138, 239.94708], [318.90277, 240.1936], [256.63416, 314.01935],
|
||||
self.face_template = np.asarray([[192.98138, 239.94708], [318.90277, 240.1936], [256.63416, 314.01935],
|
||||
[201.26117, 371.41043], [313.08905, 371.15118]])
|
||||
self.face_template = self.face_template * (face_size / 512.0)
|
||||
if self.crop_ratio[0] > 1:
|
||||
|
|
@ -144,9 +144,9 @@ class FaceRestoreHelper(object):
|
|||
continue
|
||||
|
||||
if self.template_3points:
|
||||
landmark = np.array([[bbox[i], bbox[i + 1]] for i in range(5, 11, 2)])
|
||||
landmark = np.asarray([[bbox[i], bbox[i + 1]] for i in range(5, 11, 2)])
|
||||
else:
|
||||
landmark = np.array([[bbox[i], bbox[i + 1]] for i in range(5, 15, 2)])
|
||||
landmark = np.asarray([[bbox[i], bbox[i + 1]] for i in range(5, 15, 2)])
|
||||
self.all_landmarks_5.append(landmark)
|
||||
self.det_faces.append(bbox[0:5])
|
||||
if len(self.det_faces) == 0:
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ def align_crop_face_landmarks(img,
|
|||
transform_size = output_size * 4
|
||||
|
||||
# Parse landmarks
|
||||
lm = np.array(landmarks)
|
||||
lm = np.asarray(landmarks)
|
||||
if lm.shape[0] == 5 and lm_type == 'retinaface_5':
|
||||
eye_left = lm[0]
|
||||
eye_right = lm[1]
|
||||
|
|
@ -163,7 +163,7 @@ def align_crop_face_landmarks(img,
|
|||
# Transform use cv2
|
||||
h_ratio = shrink_ratio[0] / shrink_ratio[1]
|
||||
dst_h, dst_w = int(transform_size * h_ratio), transform_size
|
||||
template = np.array([[0, 0], [0, dst_h], [dst_w, dst_h], [dst_w, 0]])
|
||||
template = np.asarray([[0, 0], [0, dst_h], [dst_w, dst_h], [dst_w, 0]])
|
||||
# use cv2.LMEDS method for the equivalence to skimage transform
|
||||
# ref: https://blog.csdn.net/yichxi/article/details/115827338
|
||||
affine_matrix = cv2.estimateAffinePartial2D(quad, template, method=cv2.LMEDS)[0]
|
||||
|
|
@ -176,11 +176,11 @@ def align_crop_face_landmarks(img,
|
|||
|
||||
if return_inverse_affine:
|
||||
dst_h, dst_w = int(output_size * h_ratio), output_size
|
||||
template = np.array([[0, 0], [0, dst_h], [dst_w, dst_h], [dst_w, 0]])
|
||||
template = np.asarray([[0, 0], [0, dst_h], [dst_w, dst_h], [dst_w, 0]])
|
||||
# use cv2.LMEDS method for the equivalence to skimage transform
|
||||
# ref: https://blog.csdn.net/yichxi/article/details/115827338
|
||||
affine_matrix = cv2.estimateAffinePartial2D(
|
||||
quad_ori, np.array([[0, 0], [0, output_size], [dst_w, dst_h], [dst_w, 0]]), method=cv2.LMEDS)[0]
|
||||
quad_ori, np.asarray([[0, 0], [0, output_size], [dst_w, dst_h], [dst_w, 0]]), method=cv2.LMEDS)[0]
|
||||
inverse_affine = cv2.invertAffineTransform(affine_matrix)
|
||||
else:
|
||||
inverse_affine = None
|
||||
|
|
@ -234,7 +234,7 @@ if __name__ == '__main__':
|
|||
bboxes = get_largest_face(bboxes, h, w)[0]
|
||||
visualize_detection(img_ori, [bboxes], f'tmp/{img_name}_det.png')
|
||||
|
||||
landmarks = np.array([[bboxes[i], bboxes[i + 1]] for i in range(5, 15, 2)])
|
||||
landmarks = np.asarray([[bboxes[i], bboxes[i + 1]] for i in range(5, 15, 2)])
|
||||
|
||||
cropped_face, inverse_affine = align_crop_face_landmarks(
|
||||
img_ori,
|
||||
|
|
|
|||
|
|
@ -104,7 +104,7 @@ def generate_mask_from_image(image: np.ndarray, mask_model: str = 'sam', extras=
|
|||
draw = ImageDraw.Draw(debug_dino_image)
|
||||
for box in boxes.numpy():
|
||||
draw.rectangle(box.tolist(), fill="white")
|
||||
return np.array(debug_dino_image), dino_detection_count, sam_detection_count, sam_detection_on_mask_count
|
||||
return np.asarray(debug_dino_image), dino_detection_count, sam_detection_count, sam_detection_on_mask_count
|
||||
|
||||
transformed_boxes = sam_predictor.transform.apply_boxes_torch(boxes, image.shape[:2])
|
||||
masks, _, _ = sam_predictor.predict_torch(
|
||||
|
|
@ -126,5 +126,5 @@ def generate_mask_from_image(image: np.ndarray, mask_model: str = 'sam', extras=
|
|||
|
||||
final_mask_tensor = (final_mask_tensor > 0).to('cpu').numpy()
|
||||
mask_image = np.dstack((final_mask_tensor, final_mask_tensor, final_mask_tensor)) * 255
|
||||
mask_image = np.array(mask_image, dtype=np.uint8)
|
||||
mask_image = np.asarray(mask_image, dtype=np.uint8)
|
||||
return mask_image, dino_detection_count, sam_detection_count, sam_detection_on_mask_count
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ def default_interrogator(image_rgb, threshold=0.35, character_threshold=0.85, ex
|
|||
square = Image.new("RGB", (height, height), (255, 255, 255))
|
||||
square.paste(image, ((height-new_size[0])//2, (height-new_size[1])//2))
|
||||
|
||||
image = np.array(square).astype(np.float32)
|
||||
image = np.asarray(square).astype(np.float32)
|
||||
image = image[:, :, ::-1] # RGB -> BGR
|
||||
image = np.expand_dims(image, 0)
|
||||
|
||||
|
|
|
|||
|
|
@ -1476,10 +1476,10 @@ class LoadImage:
|
|||
if i.mode == 'I':
|
||||
i = i.point(lambda i: i * (1 / 255))
|
||||
image = i.convert("RGB")
|
||||
image = np.array(image).astype(np.float32) / 255.0
|
||||
image = np.asarray(image).astype(np.float32) / 255.0
|
||||
image = torch.from_numpy(image)[None,]
|
||||
if 'A' in i.getbands():
|
||||
mask = np.array(i.getchannel('A')).astype(np.float32) / 255.0
|
||||
mask = np.asarray(i.getchannel('A')).astype(np.float32) / 255.0
|
||||
mask = 1. - torch.from_numpy(mask)
|
||||
else:
|
||||
mask = torch.zeros((64,64), dtype=torch.float32, device="cpu")
|
||||
|
|
@ -1536,7 +1536,7 @@ class LoadImageMask:
|
|||
mask = None
|
||||
c = channel[0].upper()
|
||||
if c in i.getbands():
|
||||
mask = np.array(i.getchannel(c)).astype(np.float32) / 255.0
|
||||
mask = np.asarray(i.getchannel(c)).astype(np.float32) / 255.0
|
||||
mask = torch.from_numpy(mask)
|
||||
if c == 'A':
|
||||
mask = 1. - mask
|
||||
|
|
|
|||
|
|
@ -327,7 +327,7 @@ class GrowMask:
|
|||
|
||||
def expand_mask(self, mask, expand, tapered_corners):
|
||||
c = 0 if tapered_corners else 1
|
||||
kernel = np.array([[c, 1, c],
|
||||
kernel = np.asarray([[c, 1, c],
|
||||
[1, 1, 1],
|
||||
[c, 1, c]])
|
||||
mask = mask.reshape((-1, mask.shape[-2], mask.shape[-1]))
|
||||
|
|
|
|||
|
|
@ -154,7 +154,7 @@ class Quantize:
|
|||
bayer_n = int(math.log2(order))
|
||||
bayer_matrix = torch.from_numpy(spread * normalized_bayer_matrix(bayer_n) + 0.5)
|
||||
|
||||
result = torch.from_numpy(np.array(im).astype(np.float32))
|
||||
result = torch.from_numpy(np.asarray(im).astype(np.float32))
|
||||
tw = math.ceil(result.shape[0] / bayer_matrix.shape[0])
|
||||
th = math.ceil(result.shape[1] / bayer_matrix.shape[1])
|
||||
tiled_matrix = bayer_matrix.tile(tw, th).unsqueeze(-1)
|
||||
|
|
@ -182,7 +182,7 @@ class Quantize:
|
|||
order = int(dither.split('-')[-1])
|
||||
quantized_image = Quantize.bayer(im, pal_im, order)
|
||||
|
||||
quantized_array = torch.tensor(np.array(quantized_image.convert("RGB"))).float() / 255
|
||||
quantized_array = torch.tensor(np.asarray(quantized_image.convert("RGB"))).float() / 255
|
||||
result[b] = quantized_array
|
||||
|
||||
return (result,)
|
||||
|
|
|
|||
|
|
@ -163,7 +163,7 @@ def betas_for_alpha_bar(num_diffusion_timesteps, alpha_bar, max_beta=0.999):
|
|||
t1 = i / num_diffusion_timesteps
|
||||
t2 = (i + 1) / num_diffusion_timesteps
|
||||
betas.append(min(1 - alpha_bar(t2) / alpha_bar(t1), max_beta))
|
||||
return np.array(betas)
|
||||
return np.asarray(betas)
|
||||
|
||||
|
||||
def extract_into_tensor(a, t, x_shape):
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ def log_txt_as_img(wh, xc, size=10):
|
|||
except UnicodeEncodeError:
|
||||
print("Cant encode string for logging. Skipping.")
|
||||
|
||||
txt = np.array(txt).transpose(2, 0, 1) / 127.5 - 1.0
|
||||
txt = np.asarray(txt).transpose(2, 0, 1) / 127.5 - 1.0
|
||||
txts.append(txt)
|
||||
txts = np.stack(txts)
|
||||
txts = torch.tensor(txts)
|
||||
|
|
|
|||
|
|
@ -374,7 +374,7 @@ def bislerp(samples, width, height):
|
|||
def lanczos(samples, width, height):
|
||||
images = [Image.fromarray(np.clip(255. * image.movedim(0, -1).cpu().numpy(), 0, 255).astype(np.uint8)) for image in samples]
|
||||
images = [image.resize((width, height), resample=Image.Resampling.LANCZOS) for image in images]
|
||||
images = [torch.from_numpy(np.array(image).astype(np.float32) / 255.0).movedim(-1, 0) for image in images]
|
||||
images = [torch.from_numpy(np.asarray(image).astype(np.float32) / 255.0).movedim(-1, 0) for image in images]
|
||||
result = torch.stack(images)
|
||||
return result.to(samples.device, samples.dtype)
|
||||
|
||||
|
|
|
|||
|
|
@ -149,7 +149,7 @@ class WMSA(nn.Module):
|
|||
|
||||
def relative_embedding(self):
|
||||
cord = torch.tensor(
|
||||
np.array(
|
||||
np.asarray(
|
||||
[
|
||||
[i, j]
|
||||
for i in range(self.window_size)
|
||||
|
|
|
|||
|
|
@ -242,7 +242,7 @@ class Image(
|
|||
if self.type == "pil":
|
||||
return im
|
||||
elif self.type == "numpy":
|
||||
return np.array(im)
|
||||
return np.asarray(im)
|
||||
elif self.type == "filepath":
|
||||
path = self.pil_to_temp_file(
|
||||
im, dir=self.DEFAULT_TEMP_DIR, format=fmt or "png"
|
||||
|
|
@ -349,7 +349,7 @@ class Image(
|
|||
x = processing_utils.decode_base64_to_image(x)
|
||||
if self.shape is not None:
|
||||
x = processing_utils.resize_and_crop(x, self.shape)
|
||||
resized_and_cropped_image = np.array(x)
|
||||
resized_and_cropped_image = np.asarray(x)
|
||||
try:
|
||||
from skimage.segmentation import slic
|
||||
except (ImportError, ModuleNotFoundError) as err:
|
||||
|
|
@ -418,7 +418,7 @@ class Image(
|
|||
x = processing_utils.decode_base64_to_image(x)
|
||||
if self.shape is not None:
|
||||
x = processing_utils.resize_and_crop(x, self.shape)
|
||||
x = np.array(x)
|
||||
x = np.asarray(x)
|
||||
output_scores = np.zeros((x.shape[0], x.shape[1]))
|
||||
|
||||
for score, mask in zip(scores, masks):
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ current_task = None
|
|||
def box_blur(x, k):
|
||||
x = Image.fromarray(x)
|
||||
x = x.filter(ImageFilter.BoxBlur(k))
|
||||
return np.array(x)
|
||||
return np.asarray(x)
|
||||
|
||||
|
||||
def max_filter_opencv(x, ksize=3):
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ def erode_or_dilate(x, k):
|
|||
def resample_image(im, width, height):
|
||||
im = Image.fromarray(im)
|
||||
im = im.resize((int(width), int(height)), resample=LANCZOS)
|
||||
return np.array(im)
|
||||
return np.asarray(im)
|
||||
|
||||
|
||||
def resize_image(im, width, height, resize_mode=1):
|
||||
|
|
@ -98,7 +98,7 @@ def resize_image(im, width, height, resize_mode=1):
|
|||
res.paste(resized.resize((fill_width, height), box=(0, 0, 0, height)), box=(0, 0))
|
||||
res.paste(resized.resize((fill_width, height), box=(resized.width, 0, resized.width, height)), box=(fill_width + src_w, 0))
|
||||
|
||||
return np.array(res)
|
||||
return np.asarray(res)
|
||||
|
||||
|
||||
def get_shape_ceil(h, w):
|
||||
|
|
|
|||
Loading…
Reference in New Issue