File tree Expand file tree Collapse file tree 1 file changed +2
-2
lines changed
code/chapter-8/08_image_retrieval/image_retrieval_server Expand file tree Collapse file tree 1 file changed +2
-2
lines changed Original file line number Diff line number Diff line change @@ -113,6 +113,7 @@ def encode_image_by_ndarray(self, image_rgb):
113113 image = self .preprocess (Image .fromarray (image_rgb )).unsqueeze (0 ).to (device )
114114 with torch .no_grad ():
115115 img_feat_vec = self .model .encode_image (image )
116+ # # 一定要Normalization!https://github.com/rom1504/clip-retrieval/blob/main/clip_retrieval/clip_back.py#L226
116117 img_feat_vec /= img_feat_vec .norm (dim = - 1 , keepdim = True )
117118 img_feat_vec = img_feat_vec .cpu ().numpy () # 1x512向量
118119
@@ -125,9 +126,8 @@ def encode_text_by_string(self, text):
125126 :return:
126127 """
127128 token = clip .tokenize ([text ]).to (self .device )
128- # # 一定要Normalization!https://github.com/rom1504/clip-retrieval/blob/main/clip_retrieval/clip_back.py#L226
129129 feat_text = self .model .encode_text (token )
130- feat_text /= feat_text .norm (dim = - 1 , keepdim = True )
130+ # feat_text /= feat_text.norm(dim=-1, keepdim=True) # !!! 图片需要Normalization,text不需要
131131 feat_text = feat_text .detach ().cpu ().numpy () # 1x512向量
132132
133133 return feat_text
You can’t perform that action at this time.
0 commit comments