Skip to content

Commit

Permalink
Optimize CLIP model loading (#309)
Browse files Browse the repository at this point in the history
* Implemented CLIPImage model persistence.
  • Loading branch information
Spiess authored May 16, 2022
1 parent 062abb6 commit d3a5b8f
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,10 @@ public class CLIPImage extends AbstractFeatureModule {
private static final float[] MEAN = new float[]{0.48145466f, 0.4578275f, 0.40821073f};
private static final float[] STD = new float[]{0.26862954f, 0.26130258f, 0.27577711f};

private SavedModelBundle model;
private static SavedModelBundle model;

public CLIPImage() {
super(TABLE_NAME, 1f, EMBEDDING_SIZE);
model = SavedModelBundle.load(RESOURCE_PATH + EMBEDDING_MODEL);
this.correspondence = CorrespondenceFunction.linear(0.5);
}

Expand Down Expand Up @@ -88,7 +87,14 @@ public List<ScoreElement> getSimilar(SegmentContainer sc, ReadableQueryConfig qc
return getSimilar(embeddingArray, queryConfig);
}

private void initializeModel() {
if (model == null) {
model = SavedModelBundle.load(RESOURCE_PATH + EMBEDDING_MODEL);
}
}

private float[] embedImage(BufferedImage img) {
initializeModel();

float[] rgb = prepareImage(img);

Expand Down

0 comments on commit d3a5b8f

Please sign in to comment.