Search in sources :

Example 86 with Image

use of com.google.cloud.compute.v1.Image in project openj9 by eclipse.

the class XMLIndexReader method _createCoreImageAfterParseError.

/**
 * This is like the setJ9DumpData method but is to be used when we fail to parse the file.  It is meant to try to construct the
 * Image object with what it was able to get
 *
 * @param e The cause of the error
 */
private void _createCoreImageAfterParseError(Exception e) {
    Builder builder = null;
    if (_stream == null) {
        // extract directly from the file
        builder = new Builder(_coreFile, _reader, 0, _fileResolvingAgent);
    } else {
        // extract using the data stream
        builder = new Builder(_coreFile, _stream, 0, _fileResolvingAgent);
    }
    _coreFile.extract(builder);
    String osType = builder.getOSType();
    String cpuType = builder.getCPUType();
    String cpuSubType = builder.getCPUSubType();
    long creationTime = builder.getCreationTime();
    _coreImage = new Image(osType, null, cpuType, cpuSubType, 0, 0, creationTime);
    Iterator spaces = builder.getAddressSpaces();
    while (spaces.hasNext()) {
        ImageAddressSpace addressSpace = (ImageAddressSpace) spaces.next();
        // Set all processes as having invalid runtimes
        for (Iterator processes = addressSpace.getProcesses(); processes.hasNext(); ) {
            ImageProcess process = (ImageProcess) processes.next();
            process.runtimeExtractionFailed(e);
        }
        _coreImage.addAddressSpace(addressSpace);
    }
}
Also used : ImageAddressSpace(com.ibm.dtfj.image.j9.ImageAddressSpace) ImageProcess(com.ibm.dtfj.image.j9.ImageProcess) Builder(com.ibm.dtfj.image.j9.Builder) Iterator(java.util.Iterator) Image(com.ibm.dtfj.image.j9.Image)

Example 87 with Image

use of com.google.cloud.compute.v1.Image in project java-automl by googleapis.

the class VisionClassificationPredict method predict.

static void predict(String projectId, String modelId, String filePath) throws IOException {
    // the "close" method on the client to safely clean up any remaining background resources.
    try (PredictionServiceClient client = PredictionServiceClient.create()) {
        // Get the full path of the model.
        ModelName name = ModelName.of(projectId, "us-central1", modelId);
        ByteString content = ByteString.copyFrom(Files.readAllBytes(Paths.get(filePath)));
        Image image = Image.newBuilder().setImageBytes(content).build();
        ExamplePayload payload = ExamplePayload.newBuilder().setImage(image).build();
        PredictRequest predictRequest = PredictRequest.newBuilder().setName(name.toString()).setPayload(payload).putParams("score_threshold", // [0.0-1.0] Only produce results higher than this value
        "0.8").build();
        PredictResponse response = client.predict(predictRequest);
        for (AnnotationPayload annotationPayload : response.getPayloadList()) {
            System.out.format("Predicted class name: %s\n", annotationPayload.getDisplayName());
            System.out.format("Predicted class score: %.2f\n", annotationPayload.getClassification().getScore());
        }
    }
}
Also used : ModelName(com.google.cloud.automl.v1.ModelName) ByteString(com.google.protobuf.ByteString) PredictResponse(com.google.cloud.automl.v1.PredictResponse) ExamplePayload(com.google.cloud.automl.v1.ExamplePayload) Image(com.google.cloud.automl.v1.Image) PredictRequest(com.google.cloud.automl.v1.PredictRequest) PredictionServiceClient(com.google.cloud.automl.v1.PredictionServiceClient) AnnotationPayload(com.google.cloud.automl.v1.AnnotationPayload)

Example 88 with Image

use of com.google.cloud.compute.v1.Image in project java-automl by googleapis.

the class VisionObjectDetectionPredict method predict.

static void predict(String projectId, String modelId, String filePath) throws IOException {
    // the "close" method on the client to safely clean up any remaining background resources.
    try (PredictionServiceClient client = PredictionServiceClient.create()) {
        // Get the full path of the model.
        ModelName name = ModelName.of(projectId, "us-central1", modelId);
        ByteString content = ByteString.copyFrom(Files.readAllBytes(Paths.get(filePath)));
        Image image = Image.newBuilder().setImageBytes(content).build();
        ExamplePayload payload = ExamplePayload.newBuilder().setImage(image).build();
        PredictRequest predictRequest = PredictRequest.newBuilder().setName(name.toString()).setPayload(payload).putParams("score_threshold", // [0.0-1.0] Only produce results higher than this value
        "0.5").build();
        PredictResponse response = client.predict(predictRequest);
        for (AnnotationPayload annotationPayload : response.getPayloadList()) {
            System.out.format("Predicted class name: %s\n", annotationPayload.getDisplayName());
            System.out.format("Predicted class score: %.2f\n", annotationPayload.getImageObjectDetection().getScore());
            BoundingPoly boundingPoly = annotationPayload.getImageObjectDetection().getBoundingBox();
            System.out.println("Normalized Vertices:");
            for (NormalizedVertex vertex : boundingPoly.getNormalizedVerticesList()) {
                System.out.format("\tX: %.2f, Y: %.2f\n", vertex.getX(), vertex.getY());
            }
        }
    }
}
Also used : ModelName(com.google.cloud.automl.v1.ModelName) ByteString(com.google.protobuf.ByteString) PredictResponse(com.google.cloud.automl.v1.PredictResponse) BoundingPoly(com.google.cloud.automl.v1.BoundingPoly) ExamplePayload(com.google.cloud.automl.v1.ExamplePayload) Image(com.google.cloud.automl.v1.Image) PredictRequest(com.google.cloud.automl.v1.PredictRequest) PredictionServiceClient(com.google.cloud.automl.v1.PredictionServiceClient) AnnotationPayload(com.google.cloud.automl.v1.AnnotationPayload) NormalizedVertex(com.google.cloud.automl.v1.NormalizedVertex)

Example 89 with Image

use of com.google.cloud.compute.v1.Image in project java-automl by googleapis.

the class PredictionApi method predict.

// [START automl_vision_predict]
/**
 * Demonstrates using the AutoML client to predict an image.
 *
 * @param projectId the Id of the project.
 * @param computeRegion the Region name.
 * @param modelId the Id of the model which will be used for text classification.
 * @param filePath the Local text file path of the content to be classified.
 * @param scoreThreshold the Confidence score. Only classifications with confidence score above
 *     scoreThreshold are displayed.
 */
static void predict(String projectId, String computeRegion, String modelId, String filePath, String scoreThreshold) {
    // Instantiate client for prediction service.
    try (PredictionServiceClient predictionClient = PredictionServiceClient.create()) {
        // Get the full path of the model.
        ModelName name = ModelName.of(projectId, computeRegion, modelId);
        // Read the image and assign to payload.
        ByteString content = ByteString.copyFrom(Files.readAllBytes(Paths.get(filePath)));
        Image image = Image.newBuilder().setImageBytes(content).build();
        ExamplePayload examplePayload = ExamplePayload.newBuilder().setImage(image).build();
        // Additional parameters that can be provided for prediction e.g. Score Threshold
        Map<String, String> params = new HashMap<>();
        if (scoreThreshold != null) {
            params.put("score_threshold", scoreThreshold);
        }
        // Perform the AutoML Prediction request
        PredictResponse response = predictionClient.predict(name, examplePayload, params);
        System.out.println("Prediction results:");
        for (AnnotationPayload annotationPayload : response.getPayloadList()) {
            System.out.println("Predicted class name :" + annotationPayload.getDisplayName());
            System.out.println("Predicted class score :" + annotationPayload.getClassification().getScore());
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : ModelName(com.google.cloud.automl.v1beta1.ModelName) HashMap(java.util.HashMap) ByteString(com.google.protobuf.ByteString) PredictResponse(com.google.cloud.automl.v1beta1.PredictResponse) ExamplePayload(com.google.cloud.automl.v1beta1.ExamplePayload) ByteString(com.google.protobuf.ByteString) IOException(java.io.IOException) Image(com.google.cloud.automl.v1beta1.Image) PredictionServiceClient(com.google.cloud.automl.v1beta1.PredictionServiceClient) AnnotationPayload(com.google.cloud.automl.v1beta1.AnnotationPayload)

Example 90 with Image

use of com.google.cloud.compute.v1.Image in project openj9 by eclipse-openj9.

the class XMLIndexReader method _createCoreImageAfterParseError.

/**
 * This is like the setJ9DumpData method but is to be used when we fail to parse the file.  It is meant to try to construct the
 * Image object with what it was able to get
 *
 * @param e The cause of the error
 */
private void _createCoreImageAfterParseError(Exception e) {
    Builder builder = null;
    if (_stream == null) {
        // extract directly from the file
        builder = new Builder(_coreFile, _reader, 0, _fileResolvingAgent);
    } else {
        // extract using the data stream
        builder = new Builder(_coreFile, _stream, 0, _fileResolvingAgent);
    }
    _coreFile.extract(builder);
    String osType = builder.getOSType();
    String cpuType = builder.getCPUType();
    String cpuSubType = builder.getCPUSubType();
    long creationTime = builder.getCreationTime();
    _coreImage = new Image(osType, null, cpuType, cpuSubType, 0, 0, creationTime);
    Iterator spaces = builder.getAddressSpaces();
    while (spaces.hasNext()) {
        ImageAddressSpace addressSpace = (ImageAddressSpace) spaces.next();
        // Set all processes as having invalid runtimes
        for (Iterator processes = addressSpace.getProcesses(); processes.hasNext(); ) {
            ImageProcess process = (ImageProcess) processes.next();
            process.runtimeExtractionFailed(e);
        }
        _coreImage.addAddressSpace(addressSpace);
    }
}
Also used : ImageAddressSpace(com.ibm.dtfj.image.j9.ImageAddressSpace) ImageProcess(com.ibm.dtfj.image.j9.ImageProcess) Builder(com.ibm.dtfj.image.j9.Builder) Iterator(java.util.Iterator) Image(com.ibm.dtfj.image.j9.Image)

Aggregations

AnnotateImageRequest (com.google.cloud.vision.v1.AnnotateImageRequest)72 Image (com.google.cloud.vision.v1.Image)72 Feature (com.google.cloud.vision.v1.Feature)70 BatchAnnotateImagesResponse (com.google.cloud.vision.v1.BatchAnnotateImagesResponse)69 ImageAnnotatorClient (com.google.cloud.vision.v1.ImageAnnotatorClient)66 ArrayList (java.util.ArrayList)64 AnnotateImageResponse (com.google.cloud.vision.v1.AnnotateImageResponse)63 ByteString (com.google.protobuf.ByteString)51 ImageSource (com.google.cloud.vision.v1.ImageSource)39 FileInputStream (java.io.FileInputStream)31 EntityAnnotation (com.google.cloud.vision.v1.EntityAnnotation)27 WebImage (com.google.cloud.vision.v1.WebDetection.WebImage)26 IOException (java.io.IOException)17 ImageContext (com.google.cloud.vision.v1.ImageContext)14 WebDetection (com.google.cloud.vision.v1.WebDetection)11 LocationInfo (com.google.cloud.vision.v1.LocationInfo)10 SafeSearchAnnotation (com.google.cloud.vision.v1.SafeSearchAnnotation)10 Arrays (java.util.Arrays)10 AttachedDisk (com.google.cloud.compute.v1.AttachedDisk)9 CropHint (com.google.cloud.vision.v1.CropHint)9