use of com.google.cloud.automl.v1beta1.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) throws IOException {
// 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());
}
}
}
use of com.google.cloud.automl.v1beta1.Image in project java-automl by googleapis.
the class ModelApi method createModel.
// [START automl_vision_create_model]
/**
* Demonstrates using the AutoML client to create a model.
*
* @param projectId the Id of the project.
* @param computeRegion the Region name.
* @param dataSetId the Id of the dataset to which model is created.
* @param modelName the Name of the model.
* @param trainBudget the Budget for training the model.
*/
static void createModel(String projectId, String computeRegion, String dataSetId, String modelName, String trainBudget) {
// Instantiates a client
try (AutoMlClient client = AutoMlClient.create()) {
// A resource that represents Google Cloud Platform location.
LocationName projectLocation = LocationName.of(projectId, computeRegion);
// Set model metadata.
ImageClassificationModelMetadata imageClassificationModelMetadata = Long.valueOf(trainBudget) == 0 ? ImageClassificationModelMetadata.newBuilder().build() : ImageClassificationModelMetadata.newBuilder().setTrainBudget(Long.valueOf(trainBudget)).build();
// Set model name and model metadata for the image dataset.
Model myModel = Model.newBuilder().setDisplayName(modelName).setDatasetId(dataSetId).setImageClassificationModelMetadata(imageClassificationModelMetadata).build();
// Create a model with the model metadata in the region.
OperationFuture<Model, OperationMetadata> response = client.createModelAsync(projectLocation, myModel);
System.out.println(String.format("Training operation name: %s", response.getInitialFuture().get().getName()));
System.out.println("Training started...");
} catch (IOException | ExecutionException | InterruptedException e) {
e.printStackTrace();
}
}
use of com.google.cloud.automl.v1beta1.Image in project openj9 by eclipse-openj9.
the class XMLIndexReader method setJ9DumpData.
public void setJ9DumpData(long environ, String osType, String osSubType, String cpuType, int cpuCount, long bytesMem, int pointerSize, Image[] imageRef, ImageAddressSpace[] addressSpaceRef, ImageProcess[] processRef) {
Builder builder = null;
if (_stream == null) {
// extract directly from the file
builder = new Builder(_coreFile, _reader, environ, _fileResolvingAgent);
} else {
// extract using the data stream
builder = new Builder(_coreFile, _stream, environ, _fileResolvingAgent);
}
_coreFile.extract(builder);
// Jazz 4961 : chamlain : NumberFormatException opening corrupt dump
if (cpuType == null)
cpuType = builder.getCPUType();
String cpuSubType = builder.getCPUSubType();
if (osType == null)
osType = builder.getOSType();
long creationTime = builder.getCreationTime();
_coreImage = new Image(osType, osSubType, cpuType, cpuSubType, cpuCount, bytesMem, creationTime);
ImageAddressSpace addressSpace = (ImageAddressSpace) builder.getAddressSpaces().next();
ImageProcess process = (ImageProcess) addressSpace.getCurrentProcess();
// If not sure, use the first address space/process pair found
for (Iterator it = builder.getAddressSpaces(); it.hasNext(); ) {
ImageAddressSpace addressSpace1 = (ImageAddressSpace) it.next();
final boolean vb = false;
if (vb)
System.out.println("address space " + addressSpace1);
_coreImage.addAddressSpace(addressSpace1);
for (Iterator it2 = addressSpace1.getProcesses(); it2.hasNext(); ) {
ImageProcess process1 = (ImageProcess) it2.next();
if (vb)
try {
System.out.println("process " + process1.getID());
} catch (DataUnavailable e) {
} catch (CorruptDataException e) {
}
if (process == null || isProcessForEnvironment(environ, addressSpace1, process1)) {
addressSpace = addressSpace1;
process = process1;
if (vb)
System.out.println("default process for Runtime");
}
}
}
if (null != process) {
// z/OS can have 64-bit or 31-bit processes, Java only reports 64-bit or 32-bit.
if (process.getPointerSize() != pointerSize && !(process.getPointerSize() == 31 && pointerSize == 32)) {
System.out.println("XML and core file pointer sizes differ " + process.getPointerSize() + "!=" + pointerSize);
}
} else {
throw new IllegalStateException("No process found in the dump.");
}
imageRef[0] = _coreImage;
addressSpaceRef[0] = addressSpace;
processRef[0] = process;
}
use of com.google.cloud.automl.v1beta1.Image in project aem-core-wcm-components by adobe.
the class ImageIT method setupBeforeEach.
@BeforeEach
public void setupBeforeEach() throws ClientException {
imageTests = new ImageTests();
imageTests.setup(adminClient, contextPath, label, Commons.rtImage_v1, rootPage, defaultPageTemplate, clientlibs, new Image());
}
use of com.google.cloud.automl.v1beta1.Image in project aem-core-wcm-components by adobe.
the class ImageIT method setupBeforeEach.
@BeforeEach
public void setupBeforeEach() throws ClientException {
clientlibs = "core.wcm.components.image.v3";
imageTests = new ImageTests();
imageTests.setup(adminClient, contextPath, label, Commons.rtImage_v3, rootPage, defaultPageTemplate, clientlibs, new Image());
}
Aggregations