Views
No views yet
1import kagglehub
2
3# Download latest version
4path = kagglehub.dataset_download("paramaggarwal/fashion-product-images-dataset")
5
6print("Path to dataset files:", path)1import tensorflow as tf
2import numpy as np
3import os
4import pickle
5from tensorflow.keras.applications.resnet50 import ResNet50, preprocess_input
6from tensorflow.keras.layers import GlobalMaxPooling2D
7from tensorflow.keras.models import Sequential
8from numpy.linalg import norm
9
10# ==============================
11# 1. BUILD MODEL
12# ==============================
13
14base_model = ResNet50(
15 weights='imagenet',
16 include_top=False,
17 input_shape=(224,224,3)
18)
19base_model.trainable = False
20
21model = Sequential([
22 base_model,
23 GlobalMaxPooling2D()
24])
25
26# ==============================
27# 2. LOAD FILENAMES (FIXED)
28# ==============================
29
30IMG_DIR = 'C:/Users/hp/.cache/kagglehub/datasets/paramaggarwal/fashion-product-images-small/versions/1/images/'
31
32image_files = os.listdir(IMG_DIR)
33
34# what we PROCESS (full paths)
35image_paths = [os.path.join(IMG_DIR, fname) for fname in image_files]
36
37# what we STORE (portable)
38filenames = image_files
39
40print("Total images:", len(filenames))
41print("Sample filenames:", filenames[:5])
42
43# ==============================
44# 3. FAST tf.data PIPELINE
45# ==============================
46
47BATCH_SIZE = 128 # You can try 64 if GPU memory is low
48
49def load_and_preprocess(path):
50 img = tf.io.read_file(path)
51 img = tf.image.decode_jpeg(img, channels=3)
52 img = tf.image.resize(img, (224,224))
53 img = preprocess_input(img)
54 return img
55
56dataset = tf.data.Dataset.from_tensor_slices(image_paths)
57dataset = dataset.map(load_and_preprocess, num_parallel_calls=tf.data.AUTOTUNE)
58dataset = dataset.batch(BATCH_SIZE)
59dataset = dataset.prefetch(tf.data.AUTOTUNE)
60
61# ==============================
62# 4. FEATURE EXTRACTION (FAST)
63# ==============================
64
65print("Extracting features...")
66features = model.predict(dataset, verbose=1)
67
68# Normalize embeddings
69features = features / norm(features, axis=1, keepdims=True)
70
71print("Feature shape:", features.shape)
72
73# ==============================
74# 5. SAVE OUTPUTS
75# ==============================
76
77pickle.dump(features, open('embeddings.pkl', 'wb'))
78pickle.dump(filenames, open('filenames.pkl', 'wb'))
79
80print("✅ Embeddings and filenames saved successfully")1import pandas as pd
2
3df = pd.read_csv(r"styles.csv" , on_bad_lines='skip')
4df['baseColour'].fillna(df['baseColour'].mode()[0] , inplace=True)
5df['season'].fillna(df['season'].mode()[0] , inplace=True)
6df['year'].fillna(df['year'].mode()[0] , inplace=True)
7df['usage'].fillna(df['usage'].mode()[0] , inplace=True)
8df.dropna(subset=['productDisplayName'] , inplace=True)
9
10print(df.head())
11print(df.isnull().sum())
12print(df.shape)
13
14print(df.columns)preprocess_inputhttps://myfashion-images-recommender.s3.ap-south-1.amazonaws.com/12345.jpg