From c7bbef5388cd44313bcd03347eccbea4af2fdb2e Mon Sep 17 00:00:00 2001 From: shihy Date: Sun, 12 Nov 2023 16:00:58 +0800 Subject: [PATCH 1/3] [Fix] Adapting to function rkme_solve_qp updates --- learnware/specification/regular/image/rkme.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/learnware/specification/regular/image/rkme.py b/learnware/specification/regular/image/rkme.py index 4421f91..df7a2a3 100644 --- a/learnware/specification/regular/image/rkme.py +++ b/learnware/specification/regular/image/rkme.py @@ -18,7 +18,7 @@ from tqdm import tqdm from . import cnn_gp from ..base import RegularStatsSpecification -from ..table.rkme import solve_qp, choose_device, setup_seed +from ..table.rkme import rkme_solve_qp, choose_device, setup_seed class RKMEImageSpecification(RegularStatsSpecification): @@ -97,6 +97,11 @@ class RKMEImageSpecification(RegularStatsSpecification): ------- """ + if len(X.shape) != 4: + raise ValueError("X should be in shape of [N, C, {0:d}, {0:d}]. ".format( + RKMEImageSpecification.IMAGE_WIDTH + )) + if ( X.shape[2] != RKMEImageSpecification.IMAGE_WIDTH or X.shape[3] != RKMEImageSpecification.IMAGE_WIDTH ) and not resize: @@ -175,7 +180,7 @@ class RKMEImageSpecification(RegularStatsSpecification): C = torch.sum(C, dim=1) / x_features.shape[0] if nonnegative_beta: - beta = solve_qp(K.double(), C.double()).to(self.device) + beta = rkme_solve_qp(K.double(), C.double())[0].to(self.device) else: beta = torch.linalg.inv(K + torch.eye(K.shape[0]).to(self.device) * 1e-5) @ C From 1d83442b855b04c7ece9cae4d6e053dfbc3082b1 Mon Sep 17 00:00:00 2001 From: shihy Date: Sun, 12 Nov 2023 16:25:33 +0800 Subject: [PATCH 2/3] [MNT] format code by black --- learnware/specification/regular/image/rkme.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/learnware/specification/regular/image/rkme.py b/learnware/specification/regular/image/rkme.py index df7a2a3..75086c2 100644 --- a/learnware/specification/regular/image/rkme.py +++ b/learnware/specification/regular/image/rkme.py @@ -98,9 +98,9 @@ class RKMEImageSpecification(RegularStatsSpecification): """ if len(X.shape) != 4: - raise ValueError("X should be in shape of [N, C, {0:d}, {0:d}]. ".format( - RKMEImageSpecification.IMAGE_WIDTH - )) + raise ValueError( + "X should be in shape of [N, C, {0:d}, {0:d}]. ".format(RKMEImageSpecification.IMAGE_WIDTH) + ) if ( X.shape[2] != RKMEImageSpecification.IMAGE_WIDTH or X.shape[3] != RKMEImageSpecification.IMAGE_WIDTH From 9be1495a2f68fe04d796bb31a9d13432ea4f37fb Mon Sep 17 00:00:00 2001 From: shihy Date: Sun, 12 Nov 2023 16:29:38 +0800 Subject: [PATCH 3/3] [MNT] modify error msg --- learnware/specification/regular/image/rkme.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/learnware/specification/regular/image/rkme.py b/learnware/specification/regular/image/rkme.py index 75086c2..5bf57fd 100644 --- a/learnware/specification/regular/image/rkme.py +++ b/learnware/specification/regular/image/rkme.py @@ -98,9 +98,7 @@ class RKMEImageSpecification(RegularStatsSpecification): """ if len(X.shape) != 4: - raise ValueError( - "X should be in shape of [N, C, {0:d}, {0:d}]. ".format(RKMEImageSpecification.IMAGE_WIDTH) - ) + raise ValueError("X should be in shape of [N, C, H, W]. ") if ( X.shape[2] != RKMEImageSpecification.IMAGE_WIDTH or X.shape[3] != RKMEImageSpecification.IMAGE_WIDTH