@NotNull public final ClarifaiInput withConcepts(@NotNull Concept... concepts) { return withConcepts(Arrays.asList(concepts)); }
@Nullable private String addInputWithConcepts(ClarifaiClient client, String url, String ...conceptIds) { List<Concept> concepts = new ArrayList<>(conceptIds.length); for (String concept : conceptIds) { concepts.add(Concept.forID(concept)); } ClarifaiInput input = ClarifaiInput.forImage(url).withConcepts(concepts); ClarifaiResponse<List<ClarifaiInput>> response = client.addInputs().plus(input).allowDuplicateURLs(true).executeSync(); if(!response.isSuccessful() || response.get().size() != 1) { return null; } return response.get().get(0).id(); }
@Test public void addMultipleInputsWithIDs() { client.addInputs() .plus( ClarifaiInput.forImage("@@sampleTrain") .withConcepts(Concept.forID("id1")), ClarifaiInput.forImage("@@sampleWedding") .withConcepts(Concept.forID("id2")) ) .allowDuplicateURLs(true) .executeSync(); }
@Test public void addInputsWithConceptsUnicode() throws UnsupportedEncodingException { // Please note: if the id used for a concept is in Unicode, for example '人', it must be URL escaped. It may be // smarter to use Unicode characters only for naming, and use hashes for concept IDs. The Java Documentation // recommends using UTF-8 for the encoding scheme. client.addInputs() .plus(ClarifaiInput.forImage("@@samplePuppy") .withConcepts( // To mark a concept as being absent, chain `.withValue(false)` Concept.forID(URLEncoder.encode("人", "UTF-8")) ) ) .allowDuplicateURLs(true) .executeSync(); }
.plus( ClarifaiInput.forImage(FERRARI_IMAGE_URL) .withConcepts( ferrari23.withValue(true) ), ClarifaiInput.forImage(FERRARI_IMAGE_URL2) .withConcepts( ferrari23.withValue(true), outdoors23.withValue(false) ), ClarifaiInput.forImage(HONDA_IMAGE_URL) .withConcepts( ferrari23.withValue(true), outdoors23 ).withGeo(PointF.at(30, -24)), ClarifaiInput.forImage(HONDA_IMAGE_URL2) .withConcepts( ferrari23.withValue(false), outdoors23 ), ClarifaiInput.forImage(FERRARI_IMAGE_URL3) .withConcepts( ferrari23.withValue(false), outdoors23 ), ClarifaiInput.forImage(TOYOTA_IMAGE_URL) .withConcepts( ferrari23.withValue(false), outdoors23
@Test public void addInputsWithConcepts() { client.addInputs() .plus(ClarifaiInput.forImage("@@samplePuppy") .withConcepts( // To mark a concept as being absent, chain `.withValue(false)` Concept.forID("boscoe") ) ) .allowDuplicateURLs(true) .executeSync(); }
@Test public void addImageWithConcepts() { client.addInputs() .plus( ClarifaiInput.forImage("@@samplePuppy") .withConcepts(Concept.forID("boscoe")) ) .allowDuplicateURLs(true) .executeSync(); }
.plus( ClarifaiInput.forInputValue(ClarifaiImage.of("@@samplePuppy")) .withConcepts( Concept.forID("boscoe") ), ClarifaiInput.forInputValue(ClarifaiImage.of("@@sampleWedding")) .withConcepts( Concept.forID("boscoe").withValue(false)
@Retry @Test public void t01a_addInputs() throws Exception { assertSuccess(client.addInputs() .plus(ClarifaiInput.forInputValue(ClarifaiImage.of(KOTLIN_LOGO_IMAGE_FILE) .withCrop(Crop.create() .top(0.1F) .left(0.1F) .bottom(0.9F) .right(0.9F) ) ) .withID("foo1") .withConcepts(Concept.forID("concept1").withValue(false)) ) ); }
.plus( ClarifaiInput.forImage(METRO_NORTH_IMAGE_URL) .withConcepts(Concept.forID("metro")), ClarifaiInput.forImage(FAMILY_IMAGE_URL) .withConcepts(Concept.forID("family"))
@Retry @Test public void t15_trainModel() { assertSuccess(client.addInputs() .plus(ClarifaiInput.forImage(PENGUIN_IMAGE_URL) .withConcepts(Concept.forID("outdoors23")) ) .allowDuplicateURLs(true) ); assertSuccess(client.trainModel(getModelID())); retryAndTimeout(2, TimeUnit.MINUTES, () -> { final ModelVersion version = assertSuccess(client.getModelByID(getModelID())).modelVersion(); assertNotNull(version); final ModelTrainingStatus status = version.status(); if (!status.isTerminalEvent()) { return false; } if (status == ModelTrainingStatus.TRAINED) { return true; } fail("Version had error while training: " + version.status()); return false; }); }