Krishan Saini
Krishan Saini

Reputation: 119

Unable to use trained custom model in AWS Bedrock

I have trained a custom model in AWS Bedrock, named amazon.titan-image-generator-v1. The generated ARN for this model is: arn:aws:bedrock:us-east-1:901111142777:custom-model/amazon.titan-image-generator-v1:0/y2jixw0ucyyy

I'm trying to use this model in my NodeJS application to generate images based on text prompts. Here is the code I'm using:


const bedrock = new BedrockRuntimeClient({ region: 'us-east-1' });

async function createImage(prompt) {
  const params = {
    modelId: 'arn:aws:bedrock:us-east-1:901111142715:custom-model/amazon.titan-image-generator-v1:0/y2jixw0uccyk',
    // modelId: 'amazon.titan-image-generator-v1',
    body: JSON.stringify({
      textToImageParams: {
        text: prompt
      },
      taskType: "TEXT_IMAGE",
      imageGenerationConfig: {
        cfgScale: 8,
        seed: 0,
        quality: "standard",
        width: 1024,
        height: 1024,
        numberOfImages: 3
      }
    }),
    // TrainingDataConfig: {
    //   S3Uri: 's3://bedrock-poc-cocreate/bedrock/'
    // },
    // OutputConfig: {
    //   S3Bucket: 'bedrock-poc-cocreate',
    //   S3Prefix: 'fine-tuned-model/'
    // }
  };

  try {
    const command = new InvokeModelCommand(params);
    console.log('command: ', command);
    const response = await bedrock.send(command);
    console.log('Image creation initiated:', response);
    // Further processing can be done based on the response
  } catch (error) {
    console.error('Error creating image:', error);
  }
}

const prompt = 'A young Indian couple, both 21 years old, standing in the garden area of their new house, looking at the camera and posed, feeling happy and accomplished, background showcases the beautiful architecture of their entire house with minimal interiors, front view of their modern house, mid shot. Canon EOS 5D Mark IV, Sigma 35mm f/1.4 Art lens, f/1.8, ISO 4000, capturing a sense of joy and celebration'; // Example prompt
createImage(prompt);

Its throwing error:

Error creating image: ValidationException: 1 validation error detected: Value 'arn:aws:bedrock:us-east-1:901111142715:custom-model/amazon.titan-image-generator-v1:0/y2jixw0uccyk' at 'modelId' failed to satisfy constraint: Member must satisfy regular expression pattern: (arn:aws(-[^:]+)?:bedrock:[a-z0-9-]{1,20}:(([0-9]{12}:custom-model/[a-z0-9-]{1,63}[.]{1}[a-z0-9-]{1,63}/[a-z0-9]{12})|(:foundation-model/[a-z0-9-]{1,63}[.]{1}[a-z0-9-]{1,63}([.:]?[a-z0-9-]{1,63}))|([0-9]{12}:imported-model/[a-z0-9]{12})|([0-9]{12}:provisioned-model/[a-z0-9]{12})))|([a-z0-9-]{1,63}[.]{1}[a-z0-9-]{1,63}([.:]?[a-z0-9-]{1,63}))|(([0-9a-zA-Z][_-]?)+)|(arn:aws(|-us-gov|-cn|-iso|-iso-b):bedrock:(|[0-9a-z-]{1,20}):(|[0-9]{12}):model-gateway/[a-zA-Z0-9-:.]+)|([a-zA-Z0-9-:.]+)

What could be causing this ValidationException and how can I resolve it? Is there a specific way to format the modelId for custom models in AWS Bedrock, or is there something else I might be missing?

Upvotes: 0

Views: 138

Answers (1)

Jesus Diaz Rivero
Jesus Diaz Rivero

Reputation: 325

Not sure if this is a bug in the AWS SDK or an error in the ARN you provided, but just playing around with regex, I can see the colon in your ARN is causing the issue. If I change the value to arn:aws:bedrock:us-east-1:901111142777:custom-model/amazon.titan-image-generator-v1/y2jixw0ucyyy(removed the :0) the regex is identified correctly. You might have to raise this to the SDK team.

Upvotes: 0

Related Questions