da-analysis / asac_4_dataanalysis

ASAC 4기 Data Analysis Project
0 stars 1 forks source link

이미지 임베딩 transfer 결과 (스탠포드 프로덕트) #16

Open syleeie2310 opened 6 months ago

syleeie2310 commented 6 months ago

이미지 임베딩 결과를 비교할 수 있어야 함

2~3가지 모델 돌려서 결과 비교할 수 있을 정도로 > 코사인 유사도를 계산해서 비교해야 함

ㄴ 데이터를 분리해서 colab 노트북으로 돌려서 결과 데이터셋을 구글 드라이브에 올려주세요.

imhs94 commented 6 months ago

https://paperswithcode.com/dataset/stanford-online-products

syleeie2310 commented 6 months ago

데이터 확인해보기

배치 사이즈 조정 (이미지 여러번 처리 하도록 하기)

resnet 2048 모델

흑백 데이터를 RGB로 바꿀수 있도록 차원 변경하기

첫번째 이미지 not found 하면 두번째 이미지를 던질 수 있게 변경

수요일에 이야기 해서 완료되면 파일을 delta lake 로 올리기

syleeie2310 commented 5 months ago

코사인 유사도 계산은 데이터브릭스에서 업로드 해서 벡터끼리 계산해서 데이터 확인하면서 작업해보기.

syleeie2310 commented 5 months ago

에러난 데이터들에 대해서 다시 돌리는 방식으로 처리 완료

데이터 업로드 완료 (dbfs 업로드 데이터)

syleeie2310 commented 5 months ago

[1번 방식] train_df2 = train_df2.withColumn('dot', F.expr('aggregate(arrays_zip(asin1_vector, asin2_vector), 0D, (acc, x) -> acc + (x.asin1_vector x.asin2_vector))')) \ .withColumn('norm1', F.expr('sqrt(aggregate(asin1_vector, 0D, (acc, x) -> acc + (x x)))')) \ .withColumn('norm2', F.expr('sqrt(aggregate(asin2_vector, 0D, (acc, x) -> acc + (x x)))')) \ .withColumn('cos_vector', F.expr('dot / (norm1 norm2)'))

[2번 방식] from pyspark.sql.types import StringType, IntegerType, StructType, StructField, DoubleType, FloatType dot_udf = F.udf(lambda x,y: float(x.dot(y)) / float(x.norm(2)*y.norm(2)), DoubleType())

[3번 방식] def cosine_similarity(vec1, vec2): return np.dot(vec1, vec2) / (np.linalg.norm(vec1) * np.linalg.norm(vec2))

cosine_similarity_udf = udf(cosine_similarity, FloatType())

syleeie2310 commented 5 months ago

https://stackoverflow.com/questions/70328519/find-cosine-similarity-between-two-columns-of-type-arraydouble-in-pyspark

syleeie2310 commented 5 months ago

https://stackoverflow.com/questions/46758768/calculating-the-cosine-similarity-between-all-the-rows-of-a-dataframe-in-pyspark

syleeie2310 commented 5 months ago

https://stackoverflow.com/questions/76162262/use-pandas-udf-to-calculate-cosine-similarity-of-two-vectors-in-pyspark

syleeie2310 commented 5 months ago

이미지 모델 관점에서 평가 어떻게 할 것인지? 비전 API 가 있다면 리서치 해서 돌린 다음에 확인해보기

https://platform.openai.com/docs/guides/vision

syleeie2310 commented 5 months ago

메타 & 리뷰 겹치는 asin 찾는다. 1번에서 소카테고리가 동일한 기준&추천 상품 조합을 만든다. (asin1, asin2) 2번 완료후 임베딩 벡터를 붙이고, 코사인 유사도를 계산한다. 근데 만약 3번이 너무 크면.. 1~2번 다시 고민 필요

syleeie2310 commented 5 months ago

co-review 코사인 벡터 기준으로 평가를 한다고 하면

  1. 소카테고리
  2. color, size
syleeie2310 commented 5 months ago

코사인 유사도 값을 5~10개 분류하신 다음에

코사인 유사도 값이 높으면 소카 비율 높은지? 컬러가 동일한 비율이 높나? 사이즈가 동일한 비율이 높은지?

imhs94 commented 5 months ago
image image
imhs94 commented 5 months ago

소카 x 소카 데이터 개수가 너무 많아서 count() 가 너무 오래걸리는 문제와,,, 코사인 유사도 비교를 위해 embedding 결과를 asin1, asin2에 join 할때 시간이 너무나 오래 걸립니다... 혹시 동일 소카 기준으로만 df 를 만들고 그중에 비율을 비교해보는 방법을 써도 괜찮을까요?

imhs94 commented 5 months ago
image
syleeie2310 commented 5 months ago

@imhs94 네 그럼 그렇게 먼저 해보시죠! 동일 소카 내 비교부터.

syleeie2310 commented 5 months ago

데이터 확인 완료 & 평가만 재확인 해서 정리할 것 (코사인 유사도 그룹 별로 컬러, 사이즈, 동일소카 비중 확인)