I am making image retrieval project. The Images are not loading #128108
Unanswered
ayaanshkk
asked this question in
Programming Help
Replies: 1 comment 7 replies
-
can I get the link to the code so that I can diagnose the problem |
Beta Was this translation helpful? Give feedback.
7 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Select Topic Area
Bug
Body
im working on image retrieval project. the images aren't loading when im running the program. i've attached a screenshot of it.
this is my index.html file-
<title>Image Search</title>Image Search
Search SearchScore: {{ score }}{% endfor %}{% endif %}
this is my offline.py-
from PIL import Image
from featureextractor import FeatureExtractor
from pathlib import Path
import numpy as np
import os
if name == '_main':
fe = FeatureExtractor()
this is my feature_extractor.py file-
import numpy as np
from PIL import Image
import torch
import clip
from torchvision import models, transforms
class FeatureExtractor:
def init(self):
# Initialize VGG16 for image feature extraction
self.vgg16 = models.vgg16(pretrained=True).features
self.vgg16.eval()
self.preprocess_vgg16 = transforms.Compose([
transforms.Resize((224, 224)),
transforms.ToTensor(),
transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
])
this is my server.py-
import numpy as np
from PIL import Image
from feature_extractor import FeatureExtractor
from datetime import datetime
from flask import Flask, request, render_template
from pathlib import Path
app = Flask(name)
Initialize the feature extractor
fe = FeatureExtractor()
Read image features
vgg16_features = []
clip_features = []
img_paths = []
Load VGG16 features
for feature_path in Path("./static/feature/vgg16").glob("*.npy"):
vgg16_features.append(np.load(feature_path))
img_paths.append(Path("./static/img") / (feature_path.stem + ".jpg"))
vgg16_features = np.array(vgg16_features)
Load CLIP features
clip_feature_paths = list(Path("./static/feature/clip").glob("*.npy"))
for feature_path in clip_feature_paths:
feature = np.load(feature_path)
if feature.size > 0:
clip_features.append(feature)
else:
print(f"Empty feature file: {feature_path}")
clip_features = np.array(clip_features)
Debugging: print shapes to ensure they are loaded correctly
print("VGG16 features shape:", vgg16_features.shape)
print("CLIP features shape:", clip_features.shape)
print("Number of image paths:", len(img_paths))
print("CLIP feature paths:", clip_feature_paths)
@app.route('/', methods=['GET', 'POST'])
def index():
if request.method == 'POST':
query = None
uploaded_img_path = None
scores = []
if name == "main":
app.run("0.0.0.0")
Beta Was this translation helpful? Give feedback.
All reactions