JoJosmin commited on
Commit
b5f066b
1 Parent(s): 6373138

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -16
app.py CHANGED
@@ -132,23 +132,19 @@ def segment_clothing(img, clothes=["Hat", "Upper-clothes", "Skirt", "Pants", "Dr
132
 
133
  def find_similar_images(query_embedding, collection, top_k=5, batch_size=500):
134
  query_embedding = query_embedding.reshape(1, -1) # 쿼리 임베딩 차원 조정
135
- all_results = []
136
 
137
- # 전체 데이터의 길이를 계산
138
- data_length = len(collection.get(include=['metadatas'])['metadatas'])
 
 
 
 
139
 
140
- for start in range(0, data_length, batch_size):
141
- end = min(start + batch_size, data_length)
142
-
143
- # 해당 배치 범위의 임베딩과 메타데이터를 가져옴
144
- all_data = collection.get(
145
- include=['embeddings', 'metadatas'],
146
- start=start,
147
- end=end
148
- )
149
-
150
- batch_embeddings = np.array(all_data['embeddings'])
151
- batch_metadatas = all_data['metadatas']
152
 
153
  # 코사인 유사도 계산
154
  similarities = cosine_similarity(query_embedding, batch_embeddings).flatten()
@@ -164,7 +160,6 @@ def find_similar_images(query_embedding, collection, top_k=5, batch_size=500):
164
 
165
 
166
 
167
-
168
  # 세션 상태 초기화
169
  if 'step' not in st.session_state:
170
  st.session_state.step = 'input'
 
132
 
133
  def find_similar_images(query_embedding, collection, top_k=5, batch_size=500):
134
  query_embedding = query_embedding.reshape(1, -1) # 쿼리 임베딩 차원 조정
 
135
 
136
+ # 모든 임베딩과 메타데이터를 한 번에 가져옴
137
+ all_data = collection.get(include=['embeddings', 'metadatas'])
138
+ all_embeddings = np.array(all_data['embeddings'])
139
+ all_metadatas = all_data['metadatas']
140
+
141
+ all_results = []
142
 
143
+ # 전체 데이터를 batch_size씩 나누어 처리
144
+ for start in range(0, len(all_embeddings), batch_size):
145
+ end = start + batch_size
146
+ batch_embeddings = all_embeddings[start:end]
147
+ batch_metadatas = all_metadatas[start:end]
 
 
 
 
 
 
 
148
 
149
  # 코사인 유사도 계산
150
  similarities = cosine_similarity(query_embedding, batch_embeddings).flatten()
 
160
 
161
 
162
 
 
163
  # 세션 상태 초기화
164
  if 'step' not in st.session_state:
165
  st.session_state.step = 'input'