@@ -783,12 +783,13 @@ static void Interpolate1DCPUFwd(const framework::ExecutionContext& ctx,
783
783
784
784
int out_w = ctx.Attr <int >(" out_w" );
785
785
auto list_new_size_tensor = ctx.MultiInput <framework::Tensor>(" SizeTensor" );
786
+ float scale_w = -1 .;
786
787
if (list_new_size_tensor.size () > 0 ) {
787
788
// have size tensor
788
789
auto new_size = get_new_shape (list_new_size_tensor);
789
790
out_w = new_size[0 ];
790
791
} else {
791
- float scale_w = -1 ;
792
+ // float scale_w = -1;
792
793
auto scale_tensor = ctx.Input <Tensor>(" Scale" );
793
794
auto scale = ctx.Attr <std::vector<float >>(" scale" );
794
795
if (scale_tensor != nullptr ) {
@@ -833,8 +834,11 @@ static void Interpolate1DCPUFwd(const framework::ExecutionContext& ctx,
833
834
834
835
float ratio_w = 0 .f ;
835
836
if (out_w > 1 ) {
837
+ float new_scale_w = 0 .f ;
838
+ new_scale_w = (scale_w > 0 ) ? static_cast <float >(1 . / scale_w)
839
+ : static_cast <float >(in_w) / out_w;
836
840
ratio_w = (align_corners) ? static_cast <float >(in_w - 1 ) / (out_w - 1 )
837
- : static_cast <float >(in_w) / out_w ;
841
+ : static_cast <float >(new_scale_w) ;
838
842
}
839
843
if (" linear" == interp_method) {
840
844
LinearInterpolation<T>(input, output, ratio_w, in_w, n, c, out_w,
@@ -856,6 +860,8 @@ static void Interpolate2DCPUFwd(const framework::ExecutionContext& ctx,
856
860
857
861
int out_h = ctx.Attr <int >(" out_h" );
858
862
int out_w = ctx.Attr <int >(" out_w" );
863
+ float scale_h = -1 ;
864
+ float scale_w = -1 ;
859
865
860
866
auto list_new_size_tensor = ctx.MultiInput <framework::Tensor>(" SizeTensor" );
861
867
if (list_new_size_tensor.size () > 0 ) {
@@ -864,8 +870,6 @@ static void Interpolate2DCPUFwd(const framework::ExecutionContext& ctx,
864
870
out_h = new_size[0 ];
865
871
out_w = new_size[1 ];
866
872
} else {
867
- float scale_h = -1 ;
868
- float scale_w = -1 ;
869
873
auto scale_tensor = ctx.Input <Tensor>(" Scale" );
870
874
auto scale = ctx.Attr <std::vector<float >>(" scale" );
871
875
if (scale_tensor != nullptr ) {
@@ -925,12 +929,18 @@ static void Interpolate2DCPUFwd(const framework::ExecutionContext& ctx,
925
929
float ratio_h = 0 .f ;
926
930
float ratio_w = 0 .f ;
927
931
if (out_h > 1 ) {
932
+ float new_scale_h = 0 .f ;
933
+ new_scale_h = (scale_h > 0 ) ? static_cast <float >(1 . / scale_h)
934
+ : static_cast <float >(in_h) / out_h;
928
935
ratio_h = (align_corners) ? static_cast <float >(in_h - 1 ) / (out_h - 1 )
929
- : static_cast <float >(in_h) / out_h ;
936
+ : static_cast <float >(new_scale_h) ;
930
937
}
931
938
if (out_w > 1 ) {
939
+ float new_scale_w = 0 .f ;
940
+ new_scale_w = (scale_w > 0 ) ? static_cast <float >(1 . / scale_w)
941
+ : static_cast <float >(in_w) / out_w;
932
942
ratio_w = (align_corners) ? static_cast <float >(in_w - 1 ) / (out_w - 1 )
933
- : static_cast <float >(in_w) / out_w ;
943
+ : static_cast <float >(new_scale_w) ;
934
944
}
935
945
936
946
if (" bilinear" == interp_method) {
@@ -962,6 +972,10 @@ static void Interpolate3DCPUFwd(const framework::ExecutionContext& ctx,
962
972
int out_h = ctx.Attr <int >(" out_h" );
963
973
int out_w = ctx.Attr <int >(" out_w" );
964
974
975
+ float scale_d = -1 ;
976
+ float scale_h = -1 ;
977
+ float scale_w = -1 ;
978
+
965
979
auto list_new_size_tensor = ctx.MultiInput <framework::Tensor>(" SizeTensor" );
966
980
if (list_new_size_tensor.size () > 0 ) {
967
981
// have size tensor
@@ -970,9 +984,6 @@ static void Interpolate3DCPUFwd(const framework::ExecutionContext& ctx,
970
984
out_h = new_size[1 ];
971
985
out_w = new_size[2 ];
972
986
} else {
973
- float scale_d = -1 ;
974
- float scale_h = -1 ;
975
- float scale_w = -1 ;
976
987
auto scale_tensor = ctx.Input <Tensor>(" Scale" );
977
988
auto scale = ctx.Attr <std::vector<float >>(" scale" );
978
989
if (scale_tensor != nullptr ) {
@@ -1043,16 +1054,25 @@ static void Interpolate3DCPUFwd(const framework::ExecutionContext& ctx,
1043
1054
float ratio_h = 0 .f ;
1044
1055
float ratio_w = 0 .f ;
1045
1056
if (out_d > 1 ) {
1057
+ float new_scale_d = 0 .f ;
1058
+ new_scale_d = (scale_d > 0 ) ? static_cast <float >(1 . / scale_d)
1059
+ : static_cast <float >(in_d) / out_d;
1046
1060
ratio_d = (align_corners) ? static_cast <float >(in_d - 1 ) / (out_d - 1 )
1047
- : static_cast <float >(in_d) / out_d ;
1061
+ : static_cast <float >(new_scale_d) ;
1048
1062
}
1049
1063
if (out_h > 1 ) {
1064
+ float new_scale_h = 0 .f ;
1065
+ new_scale_h = (scale_h > 0 ) ? static_cast <float >(1 . / scale_h)
1066
+ : static_cast <float >(in_h) / out_h;
1050
1067
ratio_h = (align_corners) ? static_cast <float >(in_h - 1 ) / (out_h - 1 )
1051
- : static_cast <float >(in_h) / out_h ;
1068
+ : static_cast <float >(new_scale_h) ;
1052
1069
}
1053
1070
if (out_w > 1 ) {
1071
+ float new_scale_w = 0 .f ;
1072
+ new_scale_w = (scale_w > 0 ) ? static_cast <float >(1 . / scale_w)
1073
+ : static_cast <float >(in_w) / out_w;
1054
1074
ratio_w = (align_corners) ? static_cast <float >(in_w - 1 ) / (out_w - 1 )
1055
- : static_cast <float >(in_w) / out_w ;
1075
+ : static_cast <float >(new_scale_w) ;
1056
1076
}
1057
1077
1058
1078
if (" trilinear" == interp_method) {
@@ -1127,8 +1147,11 @@ static void Interpolate1DCPUBwd(const framework::ExecutionContext& ctx,
1127
1147
1128
1148
float ratio_w = 0 .f ;
1129
1149
if (out_w > 1 ) {
1150
+ float new_scale_w = 0 .f ;
1151
+ new_scale_w = (scale_w > 0 ) ? static_cast <float >(1 . / scale_w)
1152
+ : static_cast <float >(in_w) / out_w;
1130
1153
ratio_w = (align_corners) ? static_cast <float >(in_w - 1 ) / (out_w - 1 )
1131
- : static_cast <float >(in_w) / out_w ;
1154
+ : static_cast <float >(new_scale_w) ;
1132
1155
}
1133
1156
if (" linear" == interp_method) {
1134
1157
LinearInterpolationGrad<T>(output_grad, input_grad, ratio_w, in_w, n, c,
@@ -1216,12 +1239,18 @@ static void Interpolate2DCPUBwd(const framework::ExecutionContext& ctx,
1216
1239
float ratio_h = 0 .f ;
1217
1240
float ratio_w = 0 .f ;
1218
1241
if (out_h > 1 ) {
1242
+ float new_scale_h = 0 .f ;
1243
+ new_scale_h = (scale_h > 0 ) ? static_cast <float >(1 . / scale_h)
1244
+ : static_cast <float >(in_h) / out_h;
1219
1245
ratio_h = (align_corners) ? static_cast <float >(in_h - 1 ) / (out_h - 1 )
1220
- : static_cast <float >(in_h) / out_h ;
1246
+ : static_cast <float >(new_scale_h) ;
1221
1247
}
1222
1248
if (out_w > 1 ) {
1249
+ float new_scale_w = 0 .f ;
1250
+ new_scale_w = (scale_w > 0 ) ? static_cast <float >(1 . / scale_w)
1251
+ : static_cast <float >(in_w) / out_w;
1223
1252
ratio_w = (align_corners) ? static_cast <float >(in_w - 1 ) / (out_w - 1 )
1224
- : static_cast <float >(in_w) / out_w ;
1253
+ : static_cast <float >(new_scale_w) ;
1225
1254
}
1226
1255
1227
1256
if (" bilinear" == interp_method) {
@@ -1327,16 +1356,25 @@ static void Interpolate3DCPUBwd(const framework::ExecutionContext& ctx,
1327
1356
float ratio_h = 0 .f ;
1328
1357
float ratio_w = 0 .f ;
1329
1358
if (out_d > 1 ) {
1359
+ float new_scale_d = 0 .f ;
1360
+ new_scale_d = (scale_d > 0 ) ? static_cast <float >(1 . / scale_d)
1361
+ : static_cast <float >(in_d) / out_d;
1330
1362
ratio_d = (align_corners) ? static_cast <float >(in_d - 1 ) / (out_d - 1 )
1331
- : static_cast <float >(in_d) / out_d ;
1363
+ : static_cast <float >(new_scale_d) ;
1332
1364
}
1333
1365
if (out_h > 1 ) {
1366
+ float new_scale_h = 0 .f ;
1367
+ new_scale_h = (scale_h > 0 ) ? static_cast <float >(1 . / scale_h)
1368
+ : static_cast <float >(in_h) / out_h;
1334
1369
ratio_h = (align_corners) ? static_cast <float >(in_h - 1 ) / (out_h - 1 )
1335
- : static_cast <float >(in_h) / out_h ;
1370
+ : static_cast <float >(new_scale_h) ;
1336
1371
}
1337
1372
if (out_w > 1 ) {
1373
+ float new_scale_w = 0 .f ;
1374
+ new_scale_w = (scale_w > 0 ) ? static_cast <float >(1 . / scale_w)
1375
+ : static_cast <float >(in_w) / out_w;
1338
1376
ratio_w = (align_corners) ? static_cast <float >(in_w - 1 ) / (out_w - 1 )
1339
- : static_cast <float >(in_w) / out_w ;
1377
+ : static_cast <float >(new_scale_w) ;
1340
1378
}
1341
1379
1342
1380
if (" trilinear" == interp_method) {
0 commit comments