@Override protected ClarifaiResponse<List<ClarifaiOutput<Concept>>> doInBackground(Void... params) { // The default Clarifai model that identifies concepts in images final ConceptModel generalModel = App.get().clarifaiClient().getDefaultModels().generalModel(); // Use this model to predict, with the image that the user just selected as the input return generalModel.predict() .withInputs(ClarifaiInput.forImage(ClarifaiImage.of(imageBytes))) .executeSync(); }
@Test public void predictViaImageBytes() { client.getDefaultModels().generalModel().predict() .withInputs( ClarifaiInput.forImage(new File("/home/user/image.jpeg")) ) .executeSync(); }
@Test public void addAnInputUsingAPubliclyAccessibleURL() { client.addInputs() .plus(ClarifaiInput.forImage("@@sampleTrain")) .allowDuplicateURLs(true) .executeSync(); }
@Retry @Test public void t20_testDemographicsModel() { ClarifaiResponse<List<ClarifaiOutput<Region>>> faceDetects = client.getDefaultModels().demographicsModel().predict() .withInputs(ClarifaiInput.forImage(STREETBAND_IMAGE_URL)) .executeSync(); Assert.assertNotNull(faceDetects.get().get(0).data().get(0).crop()); Assert.assertNotNull(faceDetects.get().get(0).data().get(0).ageAppearances()); Assert.assertNotNull(faceDetects.get().get(0).data().get(0).genderAppearances()); Assert.assertNotNull(faceDetects.get().get(0).data().get(0).multiculturalAppearances()); }
@Retry @Test public void t25_testColorModel() { ClarifaiResponse<List<ClarifaiOutput<Color>>> colors = client.getDefaultModels().colorModel().predict() .withInputs(ClarifaiInput.forImage(METRO_NORTH_IMAGE_URL)) .executeSync(); Assert.assertNotNull(colors.get()); Assert.assertNotNull(colors.get().get(0)); Assert.assertNotNull(colors.get().get(0).data()); Assert.assertNotNull(colors.get().get(0).data().get(0)); Assert.assertNotNull(colors.get().get(0).data().get(0).hex()); Assert.assertNotNull(colors.get().get(0).data().get(0).webSafeHex()); Assert.assertNotNull(colors.get().get(0).data().get(0).webSafeColorName()); }
@Test public void quickStartPredict() { final ClarifaiResponse<List<ClarifaiOutput<Concept>>> predictionResults = client.getDefaultModels().generalModel() // You can also do client.getModelByID("id") to get custom models .predict() .withInputs( ClarifaiInput.forImage("@@sampleTrain") ) .executeSync(); }
@Test public void nsfwModel() { client.getDefaultModels().nsfwModel().predict() .withInputs(ClarifaiInput.forImage("@@sampleTrain")) .executeSync(); }
@Retry @Test public void t22_testFocusModel() { ClarifaiResponse<List<ClarifaiOutput<Focus>>> focii = client.getDefaultModels().focusModel().predict() .withInputs(ClarifaiInput.forImage(STREETBAND_IMAGE_URL)) .executeSync(); Assert.assertNotNull(focii.get()); Assert.assertNotNull(focii.get().get(0)); Assert.assertNotNull(focii.get().get(0).data()); Assert.assertNotNull(focii.get().get(0).data().get(0)); Assert.assertNotNull(focii.get().get(0).data().get(0).crop()); }
@Test public void colorModel() { client.getDefaultModels().colorModel().predict() .withInputs(ClarifaiInput.forImage("@@sampleTrain")) .executeSync(); }
@Test public void faceDetectionModel() { client.getDefaultModels().faceDetectionModel().predict() .withInputs(ClarifaiInput.forImage("@@sampleTrain")) .executeSync(); }
@Test public void shouldBeCorrectForFaceConceptsModel() { ClarifaiResponse<List<ClarifaiOutput<FaceConcepts>>> response = client.getDefaultModels().celebrityModel() .predict() .withInputs(ClarifaiInput.forImage(CELEBRITY_IMAGE_URL)).executeSync(); assertTrue(response.isSuccessful()); assertNotNull(response.get().get(0).data().get(0)); }
@Test public void shouldBeSuccessfulForDemographicsModel() { ClarifaiResponse<List<ClarifaiOutput<Region>>> response = client.getDefaultModels().demographicsModel().predict() .withInputs(ClarifaiInput.forImage(CELEBRITY_IMAGE_URL)) .executeSync(); assertTrue(response.isSuccessful()); assertNotNull(response.get().get(0).data().get(0)); }
@Retry @Test public void t24_testLogoModel() { ClarifaiResponse<List<ClarifaiOutput<Logo>>> logos = client.getDefaultModels().logoModel().predict() .withInputs(ClarifaiInput.forImage(LOGO_IMAGE_URL)) .executeSync(); Assert.assertNotNull(logos.get()); Assert.assertNotNull(logos.get().get(0)); Assert.assertNotNull(logos.get().get(0).data()); }
@Retry @Test public void t16a_predictWithModel() { assertSuccess(client.predict(client.getDefaultModels().generalModel().id()) .withInputs(ClarifaiInput.forImage(KOTLIN_LOGO_IMAGE_FILE)) ); }
@Retry @Test public void t16f_predictWithModel_multi_lang() { assertSuccess(client.predict(client.getDefaultModels().generalModel().id()) .withInputs(ClarifaiInput.forImage(KOTLIN_LOGO_IMAGE_FILE)) .withLanguage("zh") ); }
@Test public void shouldBeSuccessfulWhenSpecifyingModelVersionID() { ConceptModel model = client.getDefaultModels().generalModel(); // It's reasonably safe to have this hard-coded in a test as this is the general's model version ID which is // unlikely to be ever removed. String modelVersionID = "aa9ca48295b37401f8af92ad1af0d91d"; ClarifaiResponse<List<ClarifaiOutput<Prediction>>> response = client.predict(model.id()) .withInputs(ClarifaiInput.forImage(METRO_NORTH_IMAGE_URL)) .withVersion(modelVersionID) .executeSync(); Assert.assertTrue(response.isSuccessful()); }
@Test public void predictRequestShouldReturnConceptsWhenWithPermissions() { PredictRequest<Prediction> request = makeClient( EnvVar.CLARIFAI_API_KEY_PREDICT_AND_INPUTS_MODELS_CONCEPTS_GET.value()) .predict(client.getDefaultModels().travelModel().id()) .withInputs(ClarifaiInput.forImage(FAMILY_IMAGE_URL)); ClarifaiResponse<List<ClarifaiOutput<Prediction>>> response = request.executeSync(); assertEquals(10000, response.getStatus().statusCode()); assertNotNull(response.get().get(0).model().id()); }
@Test public void predictRequestShouldReturnModelEvenWhenNoPermissions() { PredictRequest<Prediction> request = makeClient(EnvVar.CLARIFAI_API_KEY_PREDICT_AND_INPUTS_GET.value()) .predict(client.getDefaultModels().travelModel().id()) .withInputs(ClarifaiInput.forImage(FAMILY_IMAGE_URL)); ClarifaiResponse<List<ClarifaiOutput<Prediction>>> response = request.executeSync(); assertEquals(10000, response.getStatus().statusCode()); assertNotNull(response.get().get(0).model().id()); }
@Test public void t17e_searchInputsWithModel_geo() { assertSuccess(client.addInputs().plus( ClarifaiInput.forImage(METRO_NORTH_IMAGE_URL) .withGeo(PointF.at(90F, 23F)) )); assertSuccess( client.searchInputs(matchConcept(Concept.forID("outdoors23").withValue(true))) .and(SearchClause.matchImageURL(ClarifaiImage.of(METRO_NORTH_IMAGE_URL))) .and(SearchClause.matchGeo(PointF.at(90F, 23F), Radius.of(5, Radius.Unit.MILE))) .build() ); }