RosUtil.java 879 B

1234567891011121314151617181920212223242526272829303132
  1. package examples.utils;
  2. import com.alibaba.fastjson.JSONObject;
  3. import org.apache.commons.lang3.StringUtils;
  4. public class RosUtil {
  5. public static int multiClassLabel(JSONObject labelJson, String labelKey) {
  6. if (!labelJson.containsKey(labelKey) && StringUtils.isBlank(labelJson.getString(labelKey))) {
  7. return 0;
  8. }
  9. int labelValue = labelJson.getInteger(labelKey);
  10. if (labelValue <= 0) {
  11. return 0;
  12. } else if (labelValue == 1) {
  13. return 1;
  14. } else if (labelValue <= 4) {
  15. return 2;
  16. } else if (labelValue <= 8) {
  17. return 3;
  18. } else if (labelValue <= 14) {
  19. return 4;
  20. } else if (labelValue <= 21) {
  21. return 5;
  22. } else if (labelValue <= 50) {
  23. return 6;
  24. } else {
  25. return 7;
  26. }
  27. }
  28. }