org.nd4j.shade.jackson.core.JsonProcessingException Java Examples
The following examples show how to use
org.nd4j.shade.jackson.core.JsonProcessingException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ConfusionMatrixSerializer.java From deeplearning4j with Apache License 2.0 | 6 votes |
@Override public void serialize(ConfusionMatrix<Integer> cm, JsonGenerator gen, SerializerProvider provider) throws IOException, JsonProcessingException { List<Integer> classes = cm.getClasses(); Map<Integer, Multiset<Integer>> matrix = cm.getMatrix(); Map<Integer, int[][]> m2 = new LinkedHashMap<>(); for (Integer i : matrix.keySet()) { //i = Actual class Multiset<Integer> ms = matrix.get(i); int[][] arr = new int[2][ms.size()]; int used = 0; for (Integer j : ms.elementSet()) { int count = ms.count(j); arr[0][used] = j; //j = Predicted class arr[1][used] = count; //prediction count used++; } m2.put(i, arr); } gen.writeStartObject(); gen.writeObjectField("classes", classes); gen.writeObjectField("matrix", m2); gen.writeEndObject(); }
Example #2
Source File: DataFormatDeserializer.java From deeplearning4j with Apache License 2.0 | 6 votes |
@Override public DataFormat deserialize(JsonParser jp, DeserializationContext deserializationContext) throws IOException, JsonProcessingException { JsonNode node = jp.getCodec().readTree(jp); String text = node.textValue(); switch (text){ case "NCHW": return CNN2DFormat.NCHW; case "NHWC": return CNN2DFormat.NHWC; case "NCW": return RNNFormat.NCW; case "NWC": return RNNFormat.NWC; default: return null; } }
Example #3
Source File: LegacyIntArrayDeserializer.java From deeplearning4j with Apache License 2.0 | 6 votes |
@Override public int[] deserialize(JsonParser jp, DeserializationContext deserializationContext) throws IOException, JsonProcessingException { JsonNode n = jp.getCodec().readTree(jp); if(n.isArray()){ ArrayNode an = (ArrayNode)n; int size = an.size(); int[] out = new int[size]; for( int i=0; i<size; i++ ){ out[i] = an.get(i).asInt(); } return out; } else if(n.isNumber()){ int v = n.asInt(); return new int[]{v,v}; } else { throw new IllegalStateException("Could not deserialize value: " + n); } }
Example #4
Source File: BoundingBoxesDeserializer.java From deeplearning4j with Apache License 2.0 | 5 votes |
@Override public INDArray deserialize(JsonParser jp, DeserializationContext deserializationContext) throws IOException, JsonProcessingException { JsonNode node = jp.getCodec().readTree(jp); if(node.has("dataBuffer")){ //Must be legacy format serialization JsonNode arr = node.get("dataBuffer"); int rank = node.get("rankField").asInt(); int numElements = node.get("numElements").asInt(); int offset = node.get("offsetField").asInt(); JsonNode shape = node.get("shapeField"); JsonNode stride = node.get("strideField"); int[] shapeArr = new int[rank]; int[] strideArr = new int[rank]; DataBuffer buff = Nd4j.createBuffer(numElements); for (int i = 0; i < numElements; i++) { buff.put(i, arr.get(i).asDouble()); } String ordering = node.get("orderingField").asText(); for (int i = 0; i < rank; i++) { shapeArr[i] = shape.get(i).asInt(); strideArr[i] = stride.get(i).asInt(); } return Nd4j.create(buff, shapeArr, strideArr, offset, ordering.charAt(0)); } //Standard/new format return new NDArrayTextDeSerializer().deserialize(node); }
Example #5
Source File: SharedTrainingMaster.java From deeplearning4j with Apache License 2.0 | 5 votes |
@Override public String toJson() { ObjectMapper om = getJsonMapper(); try { return om.writeValueAsString(this); } catch (JsonProcessingException e) { throw new RuntimeException("Error producing JSON representation for ParameterAveragingTrainingMaster", e); } }
Example #6
Source File: SharedTrainingMaster.java From deeplearning4j with Apache License 2.0 | 5 votes |
@Override public String toYaml() { ObjectMapper om = getYamlMapper(); try { return om.writeValueAsString(this); } catch (JsonProcessingException e) { throw new RuntimeException("Error producing YAML representation for ParameterAveragingTrainingMaster", e); } }
Example #7
Source File: NearestNeighborsClient.java From deeplearning4j with Apache License 2.0 | 5 votes |
public String writeValue(Object value) { try { return jacksonObjectMapper.writeValueAsString(value); } catch (JsonProcessingException e) { throw new RuntimeException(e); } }
Example #8
Source File: JsonMapper.java From deeplearning4j with Apache License 2.0 | 5 votes |
public static String asJson(Object o){ try{ return getMapper().writeValueAsString(o); } catch (JsonProcessingException e){ throw new RuntimeException(e); } }
Example #9
Source File: DL4JConfiguration.java From deeplearning4j with Apache License 2.0 | 5 votes |
/** * Yaml mapping * @return */ public String toYaml() { try { return YamlMapper.getMapper().writeValueAsString(this); } catch (JsonProcessingException e) { throw new RuntimeException(e); } }
Example #10
Source File: DL4JConfiguration.java From deeplearning4j with Apache License 2.0 | 5 votes |
/** * Json mapping * @return */ public String toJson() { try { return JsonMapper.getMapper().writeValueAsString(this); } catch (JsonProcessingException e) { throw new RuntimeException(e); } }
Example #11
Source File: BaseNetworkSpace.java From deeplearning4j with Apache License 2.0 | 5 votes |
/** * Return a json configuration of this configuration space. * * @return */ public String toJson() { try { return JsonMapper.getMapper().writeValueAsString(this); } catch (JsonProcessingException e) { throw new RuntimeException(e); } }
Example #12
Source File: BaseNetworkSpace.java From deeplearning4j with Apache License 2.0 | 5 votes |
/** * Return a yaml configuration of this configuration space. * * @return */ public String toYaml() { try { return YamlMapper.getMapper().writeValueAsString(this); } catch (JsonProcessingException e) { throw new RuntimeException(e); } }
Example #13
Source File: GraphConfiguration.java From deeplearning4j with Apache License 2.0 | 5 votes |
/** * Yaml mapping * @return */ public String toYaml() { try { return YamlMapper.getMapper().writeValueAsString(this); } catch (JsonProcessingException e) { throw new RuntimeException(e); } }
Example #14
Source File: GraphConfiguration.java From deeplearning4j with Apache License 2.0 | 5 votes |
/** * Json mapping * @return */ public String toJson() { try { return JsonMapper.getMapper().writeValueAsString(this); } catch (JsonProcessingException e) { throw new RuntimeException(e); } }
Example #15
Source File: OptimizationConfiguration.java From deeplearning4j with Apache License 2.0 | 5 votes |
/** * Return a json configuration of this optimization configuration * * @return */ public String toJson() { try { return JsonMapper.getMapper().writeValueAsString(this); } catch (JsonProcessingException e) { throw new RuntimeException(e); } }
Example #16
Source File: ArbiterModule.java From deeplearning4j with Apache License 2.0 | 5 votes |
private String asJson(Object o){ try{ return JsonMappers.getMapper().writeValueAsString(o); } catch (JsonProcessingException e){ throw new RuntimeException("Error converting object to JSON", e); } }
Example #17
Source File: AbstractCache.java From deeplearning4j with Apache License 2.0 | 5 votes |
public String toJson() throws JsonProcessingException { JsonObject retVal = new JsonObject(); ObjectMapper mapper = mapper(); Iterator<T> iter = vocabulary.values().iterator(); Class clazz = null; if (iter.hasNext()) clazz = iter.next().getClass(); else return retVal.getAsString(); retVal.addProperty(CLASS_FIELD, mapper.writeValueAsString(this.getClass().getName())); JsonArray jsonValues = new JsonArray(); for (T value : vocabulary.values()) { JsonObject item = new JsonObject(); item.addProperty(CLASS_FIELD, mapper.writeValueAsString(clazz)); item.addProperty(VOCAB_ITEM_FIELD, mapper.writeValueAsString(value)); jsonValues.add(item); } retVal.add(VOCAB_LIST_FIELD, jsonValues); retVal.addProperty(DOC_CNT_FIELD, mapper.writeValueAsString(documentsCounter.longValue())); retVal.addProperty(MINW_FREQ_FIELD, mapper.writeValueAsString(minWordFrequency)); retVal.addProperty(HUGE_MODEL_FIELD, mapper.writeValueAsString(hugeModelExpected)); retVal.addProperty(STOP_WORDS_FIELD, mapper.writeValueAsString(stopWords)); retVal.addProperty(SCAVENGER_FIELD, mapper.writeValueAsString(scavengerThreshold)); retVal.addProperty(RETENTION_FIELD, mapper.writeValueAsString(retentionDelay)); retVal.addProperty(TOTAL_WORD_FIELD, mapper.writeValueAsString(totalWordCount.longValue())); return retVal.toString(); }
Example #18
Source File: MemoryReport.java From deeplearning4j with Apache License 2.0 | 5 votes |
public String toYaml() { try { return NeuralNetConfiguration.mapperYaml().writeValueAsString(this); } catch (JsonProcessingException e) { throw new RuntimeException(e); } }
Example #19
Source File: MemoryReport.java From deeplearning4j with Apache License 2.0 | 5 votes |
public String toJson() { try { return NeuralNetConfiguration.mapper().writeValueAsString(this); } catch (JsonProcessingException e) { throw new RuntimeException(e); } }
Example #20
Source File: FineTuneConfiguration.java From deeplearning4j with Apache License 2.0 | 5 votes |
public String toYaml() { try { return NeuralNetConfiguration.mapperYaml().writeValueAsString(this); } catch (JsonProcessingException e) { throw new RuntimeException(e); } }
Example #21
Source File: FineTuneConfiguration.java From deeplearning4j with Apache License 2.0 | 5 votes |
public String toJson() { try { return NeuralNetConfiguration.mapper().writeValueAsString(this); } catch (JsonProcessingException e) { throw new RuntimeException(e); } }
Example #22
Source File: ROCArraySerializer.java From deeplearning4j with Apache License 2.0 | 5 votes |
@Override public void serialize(ROC[] rocs, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException, JsonProcessingException { jsonGenerator.writeStartArray(); for (ROC r : rocs) { jsonGenerator.writeStartObject(); jsonGenerator.writeStringField("@class", ROC.class.getName()); serializer.serialize(r, jsonGenerator, serializerProvider); jsonGenerator.writeEndObject(); } jsonGenerator.writeEndArray(); }
Example #23
Source File: ConfusionMatrixDeserializer.java From deeplearning4j with Apache License 2.0 | 5 votes |
@Override public ConfusionMatrix<Integer> deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { JsonNode n = jp.getCodec().readTree(jp); //Get class names/labels ArrayNode classesNode = (ArrayNode) n.get("classes"); List<Integer> classes = new ArrayList<>(); for (JsonNode cn : classesNode) { classes.add(cn.asInt()); } ConfusionMatrix<Integer> cm = new ConfusionMatrix<>(classes); ObjectNode matrix = (ObjectNode) n.get("matrix"); Iterator<Map.Entry<String, JsonNode>> matrixIter = matrix.fields(); while (matrixIter.hasNext()) { Map.Entry<String, JsonNode> e = matrixIter.next(); int actualClass = Integer.parseInt(e.getKey()); ArrayNode an = (ArrayNode) e.getValue(); ArrayNode innerMultiSetKey = (ArrayNode) an.get(0); ArrayNode innerMultiSetCount = (ArrayNode) an.get(1); Iterator<JsonNode> iterKey = innerMultiSetKey.iterator(); Iterator<JsonNode> iterCnt = innerMultiSetCount.iterator(); while (iterKey.hasNext()) { int predictedClass = iterKey.next().asInt(); int count = iterCnt.next().asInt(); cm.add(actualClass, predictedClass, count); } } return cm; }
Example #24
Source File: BaseCurve.java From deeplearning4j with Apache License 2.0 | 5 votes |
/** * @return YAML representation of the curve */ public String toYaml() { try { return JsonMappers.getYamlMapper().writeValueAsString(this); } catch (JsonProcessingException e) { throw new RuntimeException(e); } }
Example #25
Source File: BaseCurve.java From deeplearning4j with Apache License 2.0 | 5 votes |
/** * @return JSON representation of the curve */ public String toJson() { try { return JsonMappers.getMapper().writeValueAsString(this); } catch (JsonProcessingException e) { throw new RuntimeException(e); } }
Example #26
Source File: BaseHistogram.java From deeplearning4j with Apache License 2.0 | 5 votes |
/** * @return YAML representation of the curve */ public String toYaml() { try { return JsonMappers.getYamlMapper().writeValueAsString(this); } catch (JsonProcessingException e) { throw new RuntimeException(e); } }
Example #27
Source File: BaseHistogram.java From deeplearning4j with Apache License 2.0 | 5 votes |
/** * @return JSON representation of the curve */ public String toJson() { try { return JsonMappers.getMapper().writeValueAsString(this); } catch (JsonProcessingException e) { throw new RuntimeException(e); } }
Example #28
Source File: BaseEvaluation.java From deeplearning4j with Apache License 2.0 | 5 votes |
/** * @return YAML representation of the evaluation instance */ @Override public String toYaml() { try { return JsonMappers.getYamlMapper().writeValueAsString(this); } catch (JsonProcessingException e) { throw new RuntimeException(e); } }
Example #29
Source File: BaseEvaluation.java From deeplearning4j with Apache License 2.0 | 5 votes |
/** * @return JSON representation of the evaluation instance */ @Override public String toJson() { try { return JsonMappers.getMapper().writeValueAsString(this); } catch (JsonProcessingException e) { throw new RuntimeException(e); } }
Example #30
Source File: SynchronousParameterUpdater.java From deeplearning4j with Apache License 2.0 | 5 votes |
/** * Serialize this updater as json * * @return */ @Override public String toJson() { try { return objectMapper.writeValueAsString(status()); } catch (JsonProcessingException e) { throw new RuntimeException(e); } }