-
Notifications
You must be signed in to change notification settings - Fork 167
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add image annotate example #1687
Open
Ekrekr
wants to merge
1
commit into
main
Choose a base branch
from
image-annotate-example
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
config { | ||
type: "operations", | ||
hasOutput: true | ||
} | ||
|
||
-- Create the object table for the images | ||
CREATE EXTERNAL TABLE IF NOT EXISTS | ||
${self()} | ||
WITH CONNECTION `us.gcs` OPTIONS( object_metadata = 'SIMPLE', | ||
uris = ['${constants.IMAGE_BUCKET}'] ); |
25 changes: 25 additions & 0 deletions
25
examples/image_annotate/definitions/annotated_imagesets.sqlx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
config { | ||
type: "incremental" | ||
} | ||
|
||
SELECT | ||
* | ||
FROM | ||
${ref("object_table")} | ||
WHERE | ||
ml_annotate_image_status NOT LIKE "${constants.RETRYABLE_ERROR}" | ||
${ | ||
when(incremental(), `AND | ||
${constants.MERGE_COLUMN} NOT IN ( | ||
SELECT | ||
${constants.MERGE_COLUMN} | ||
FROM | ||
${self()}) | ||
OR updated > ( | ||
SELECT | ||
MAX(updated) | ||
FROM | ||
${self()})`) | ||
} | ||
LIMIT | ||
${constants.BATCH_SIZE} |
10 changes: 10 additions & 0 deletions
10
examples/image_annotate/definitions/annotated_imagesets_errors.sqlx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
config { | ||
type: "assertion" | ||
} | ||
|
||
SELECT | ||
* | ||
FROM | ||
${ref("object_table")} | ||
WHERE | ||
ml_annotate_image_status LIKE "${constants.RETRYABLE_ERROR}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
config { | ||
type: "table", | ||
} | ||
|
||
SELECT | ||
* | ||
FROM | ||
ML.ANNOTATE_IMAGE( MODEL ${ref("vision_model")}, | ||
TABLE ${ref("unannotated_imagesets")}, | ||
STRUCT(['LABEL_DETECTION'] AS vision_features)) |
19 changes: 19 additions & 0 deletions
19
examples/image_annotate/definitions/unannotated_imagesets.sqlx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
config { | ||
type: "view" | ||
} | ||
|
||
js { | ||
// Ref is avoided here to avoid the circular dependency chain. | ||
const ANNOTATED_IMAGESETS = `${ctx.schema()}` + ".annotated_imagesets" | ||
} | ||
|
||
SELECT | ||
* | ||
FROM | ||
${ref("all_imagesets")} | ||
LEFT JOIN | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
`${ANNOTATED_IMAGESETS}` | ||
ON | ||
${ref("all_imagesets")}.uri = `${ANNOTATED_IMAGESETS}`.uri | ||
WHERE | ||
`${ANNOTATED_IMAGESETS}`.uri IS NULL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
config { | ||
type: "operations", | ||
hasOutput: true | ||
} | ||
|
||
-- Model for connecting to the Vision API | ||
CREATE MODEL IF NOT EXISTS | ||
${self()} REMOTE | ||
WITH CONNECTION `us.gcs` OPTIONS (remote_service_type = 'cloud_ai_vision_v1'); |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports = { | ||
BATCH_SIZE: 100, | ||
MERGE_COLUMN: "uri", | ||
RETRYABLE_ERROR: "A retryable error occurred:", | ||
IMAGE_BUCKET: "gs://example-bucket/imagesets/*" | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Image Annotate | ||
|
||
Use BigQuery ML to annotate images from a GCS bucket. | ||
|
||
Images where annotation failed are filtered out, and retried in subsequent runs. | ||
|
||
![Image Annotation DAG](./image-annotation-dag.png?raw=true "Image Annotation DAG") | ||
|
||
<!-- TODO(ekrekr): add more info on setting up BigQuery connections. --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
defaultProject: dataform-demos | ||
defaultLocation: US | ||
defaultDataset: sample | ||
defaultAssertionDataset: sample_assertions |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is field coming from? I don't see it listed in the output of ML.ANNOTATE_IMAGE
https://cloud.google.com/bigquery/docs/reference/standard-sql/bigqueryml-syntax-annotate-image
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, why do you need that bit given the above?