i want just load images, not links
- User
i want just load images, not links
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
i want just load images, not links
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
To simplify your script so that it loads images directly from a directory (without creating symbolic links), you can follow this streamlined version. This version focuses on:
Path().glob()This example includes .jpg, .jpeg, .png, .bmp, and .webp by default. You can expand or reduce this list depending on the file types in your dataset.
import lightly_train
import pandas as pd
from tqdm import tqdm
from pathlib import Path
def load_image_paths(directory, extensions=("*.jpg", "*.jpeg", "*.png", "*.bmp", "*.webp")):
"""Load paths of image files from a directory."""
image_paths = []
directory = Path(directory)
for ext in extensions:
image_paths.extend(directory.glob(ext))
return pd.DataFrame({'path': [str(p) for p in image_paths]})
if __name__ == "__main__":
# Directory containing your image files
image_dir = "/path/to/your/images"
# Load all image paths
df = load_image_paths(image_dir)
# Optional: sample up to 10,000 images
df = df.sample(min(10000, len(df)), random_state=42) # Fix seed for reproducibility
# Create embeddings
lightly_train.embed(
out="exported_images.pt",
data=df['path'].to_list(),
checkpoint="last.ckpt",
format="torch",
overwrite=True
)
load_image_paths function uses Path().glob() to find files matching common image extensions.**/*.<ext> (e.g., **/*.jpg) to search recursively.sample() call is optional. If you want to embed all images, simply remove that line."/path/to/your/images" with the actual path to your image directory.If you're unsure whether all files exist or want extra safety:
df = df[df['path'].apply(lambda x: Path(x).exists())]
This filters out any paths that point to missing files.
This updated script should now cleanly load your images and generate embeddings without the overhead of symbolic links. Let me know if you'd like to add support for recursive subdirectories or batch processing!