diff --git a/elevate/lynx/__pycache__/views.cpython-39.pyc b/elevate/lynx/__pycache__/views.cpython-39.pyc index 3ff4ca4d..d13688c9 100644 Binary files a/elevate/lynx/__pycache__/views.cpython-39.pyc and b/elevate/lynx/__pycache__/views.cpython-39.pyc differ diff --git a/elevate/lynx/static/10054.jpg b/elevate/lynx/static/10054.jpg deleted file mode 100644 index f4e1b537..00000000 Binary files a/elevate/lynx/static/10054.jpg and /dev/null differ diff --git a/elevate/lynx/static/1163.jpg b/elevate/lynx/static/1163.jpg deleted file mode 100644 index 67e96bdd..00000000 Binary files a/elevate/lynx/static/1163.jpg and /dev/null differ diff --git a/elevate/lynx/static/1535.jpg b/elevate/lynx/static/1535.jpg deleted file mode 100644 index 985fd66e..00000000 Binary files a/elevate/lynx/static/1535.jpg and /dev/null differ diff --git a/elevate/lynx/static/1571.jpg b/elevate/lynx/static/1571.jpg deleted file mode 100644 index 4baff1e7..00000000 Binary files a/elevate/lynx/static/1571.jpg and /dev/null differ diff --git a/elevate/lynx/static/24539.jpg b/elevate/lynx/static/24539.jpg deleted file mode 100644 index 8fdcbd1f..00000000 Binary files a/elevate/lynx/static/24539.jpg and /dev/null differ diff --git a/elevate/lynx/static/28456.jpg b/elevate/lynx/static/28456.jpg deleted file mode 100644 index 5f69f429..00000000 Binary files a/elevate/lynx/static/28456.jpg and /dev/null differ diff --git a/elevate/lynx/static/35545.jpg b/elevate/lynx/static/35545.jpg deleted file mode 100644 index 7d6dc3de..00000000 Binary files a/elevate/lynx/static/35545.jpg and /dev/null differ diff --git a/elevate/lynx/static/37802.jpg b/elevate/lynx/static/37802.jpg deleted file mode 100644 index fc8b44fd..00000000 Binary files a/elevate/lynx/static/37802.jpg and /dev/null differ diff --git a/elevate/lynx/static/3818.jpg b/elevate/lynx/static/3818.jpg deleted file mode 100644 index 4f2ea107..00000000 Binary files a/elevate/lynx/static/3818.jpg and /dev/null differ diff --git a/elevate/lynx/static/39921.jpg b/elevate/lynx/static/39921.jpg deleted file mode 100644 index f76a1dea..00000000 Binary files a/elevate/lynx/static/39921.jpg and /dev/null differ diff --git a/elevate/lynx/static/41653.jpg b/elevate/lynx/static/41653.jpg deleted file mode 100644 index ad39d313..00000000 Binary files a/elevate/lynx/static/41653.jpg and /dev/null differ diff --git a/elevate/lynx/static/41784.jpg b/elevate/lynx/static/41784.jpg deleted file mode 100644 index 9d3e55ea..00000000 Binary files a/elevate/lynx/static/41784.jpg and /dev/null differ diff --git a/elevate/lynx/static/41785.jpg b/elevate/lynx/static/41785.jpg deleted file mode 100644 index 0be119c9..00000000 Binary files a/elevate/lynx/static/41785.jpg and /dev/null differ diff --git a/elevate/lynx/static/41786.jpg b/elevate/lynx/static/41786.jpg deleted file mode 100644 index 8d09b72c..00000000 Binary files a/elevate/lynx/static/41786.jpg and /dev/null differ diff --git a/elevate/lynx/static/43570.jpg b/elevate/lynx/static/43570.jpg deleted file mode 100644 index 3fdf5bde..00000000 Binary files a/elevate/lynx/static/43570.jpg and /dev/null differ diff --git a/elevate/lynx/static/50295.jpg b/elevate/lynx/static/50295.jpg deleted file mode 100644 index 4ab07244..00000000 Binary files a/elevate/lynx/static/50295.jpg and /dev/null differ diff --git a/elevate/lynx/static/50308.jpg b/elevate/lynx/static/50308.jpg deleted file mode 100644 index 1ae97c19..00000000 Binary files a/elevate/lynx/static/50308.jpg and /dev/null differ diff --git a/elevate/lynx/static/50316.jpg b/elevate/lynx/static/50316.jpg deleted file mode 100644 index 18732e1d..00000000 Binary files a/elevate/lynx/static/50316.jpg and /dev/null differ diff --git a/elevate/lynx/static/51396.jpg b/elevate/lynx/static/51396.jpg deleted file mode 100644 index bf0d8a32..00000000 Binary files a/elevate/lynx/static/51396.jpg and /dev/null differ diff --git a/elevate/lynx/static/51397.jpg b/elevate/lynx/static/51397.jpg deleted file mode 100644 index df0fdb3f..00000000 Binary files a/elevate/lynx/static/51397.jpg and /dev/null differ diff --git a/elevate/lynx/static/52435.jpg b/elevate/lynx/static/52435.jpg deleted file mode 100644 index d62edcf5..00000000 Binary files a/elevate/lynx/static/52435.jpg and /dev/null differ diff --git a/elevate/lynx/static/59018.jpg b/elevate/lynx/static/59018.jpg deleted file mode 100644 index badf13a4..00000000 Binary files a/elevate/lynx/static/59018.jpg and /dev/null differ diff --git a/elevate/lynx/static/59020.jpg b/elevate/lynx/static/59020.jpg deleted file mode 100644 index 2638bb3c..00000000 Binary files a/elevate/lynx/static/59020.jpg and /dev/null differ diff --git a/elevate/lynx/static/59021.jpg b/elevate/lynx/static/59021.jpg deleted file mode 100644 index 918eac06..00000000 Binary files a/elevate/lynx/static/59021.jpg and /dev/null differ diff --git a/elevate/lynx/static/59025.jpg b/elevate/lynx/static/59025.jpg deleted file mode 100644 index cfd5f4bd..00000000 Binary files a/elevate/lynx/static/59025.jpg and /dev/null differ diff --git a/elevate/lynx/static/59026.jpg b/elevate/lynx/static/59026.jpg deleted file mode 100644 index 843613c3..00000000 Binary files a/elevate/lynx/static/59026.jpg and /dev/null differ diff --git a/elevate/lynx/static/59027.jpg b/elevate/lynx/static/59027.jpg deleted file mode 100644 index 9877cd72..00000000 Binary files a/elevate/lynx/static/59027.jpg and /dev/null differ diff --git a/elevate/lynx/static/59028.jpg b/elevate/lynx/static/59028.jpg deleted file mode 100644 index 2358b87c..00000000 Binary files a/elevate/lynx/static/59028.jpg and /dev/null differ diff --git a/elevate/lynx/static/59029.jpg b/elevate/lynx/static/59029.jpg deleted file mode 100644 index a1b8384c..00000000 Binary files a/elevate/lynx/static/59029.jpg and /dev/null differ diff --git a/elevate/lynx/static/59030.jpg b/elevate/lynx/static/59030.jpg deleted file mode 100644 index dc05adda..00000000 Binary files a/elevate/lynx/static/59030.jpg and /dev/null differ diff --git a/elevate/lynx/static/59031.jpg b/elevate/lynx/static/59031.jpg deleted file mode 100644 index fbcc66f2..00000000 Binary files a/elevate/lynx/static/59031.jpg and /dev/null differ diff --git a/elevate/lynx/static/59033.jpg b/elevate/lynx/static/59033.jpg deleted file mode 100644 index 0bd4d51c..00000000 Binary files a/elevate/lynx/static/59033.jpg and /dev/null differ diff --git a/elevate/lynx/static/59035.jpg b/elevate/lynx/static/59035.jpg deleted file mode 100644 index 7388f04c..00000000 Binary files a/elevate/lynx/static/59035.jpg and /dev/null differ diff --git a/elevate/lynx/static/59042.jpg b/elevate/lynx/static/59042.jpg deleted file mode 100644 index d735e8a7..00000000 Binary files a/elevate/lynx/static/59042.jpg and /dev/null differ diff --git a/elevate/lynx/static/59043.jpg b/elevate/lynx/static/59043.jpg deleted file mode 100644 index 923c9f40..00000000 Binary files a/elevate/lynx/static/59043.jpg and /dev/null differ diff --git a/elevate/lynx/static/59045.jpg b/elevate/lynx/static/59045.jpg deleted file mode 100644 index 421adb69..00000000 Binary files a/elevate/lynx/static/59045.jpg and /dev/null differ diff --git a/elevate/lynx/static/59225.jpg b/elevate/lynx/static/59225.jpg deleted file mode 100644 index 15b6b328..00000000 Binary files a/elevate/lynx/static/59225.jpg and /dev/null differ diff --git a/elevate/lynx/static/59966.jpg b/elevate/lynx/static/59966.jpg deleted file mode 100644 index db58b5e4..00000000 Binary files a/elevate/lynx/static/59966.jpg and /dev/null differ diff --git a/elevate/lynx/static/59967.jpg b/elevate/lynx/static/59967.jpg deleted file mode 100644 index b5dc51d4..00000000 Binary files a/elevate/lynx/static/59967.jpg and /dev/null differ diff --git a/elevate/lynx/static/59969.jpg b/elevate/lynx/static/59969.jpg deleted file mode 100644 index 1130df63..00000000 Binary files a/elevate/lynx/static/59969.jpg and /dev/null differ diff --git a/elevate/lynx/views.py b/elevate/lynx/views.py index 55e8a0fb..8473a426 100644 --- a/elevate/lynx/views.py +++ b/elevate/lynx/views.py @@ -1,3 +1,4 @@ +import heapq from django.shortcuts import render from numpy import loadtxt import pandas as pd @@ -168,7 +169,22 @@ def N_mas_parecidas(imagen,n,imagenes): return recomendadas +def N_mas_parecidas_optimizada(imagen,n,imagenes): + + vec1 = img2vec.get_vec(imagen, tensor=True).reshape(512) #representación vectorial imagen de entrada + + heap=[] #lista de tuplas (similitud,imagen) + for im in imagenes: + candidata = Image.open('lynx'+im.get('url')) + vec2 = img2vec.get_vec(candidata.convert('RGB'), tensor=True).reshape(512) + cos_sim = cos(vec1.unsqueeze(0),vec2.unsqueeze(0)) + if(cos_sim<1): #no quiero devolver la propia imagen cono recomendación + + heapq.heappush(heap, (round(cos_sim.item(),7), im.get('name'))) + + + return heapq.nlargest(n, heap) # - Homepage def home(request): @@ -279,6 +295,126 @@ def image_detail(request, image_name): form = IntegerForm(img=img, images=images) + if request.method == 'POST': + form = IntegerForm(request.POST, img=img, images=images) + if form.is_valid(): + n = form.cleaned_data['integer_field'] + recomendadas = N_mas_parecidas_optimizada(img, n, images) + + similares = [] + + for tupla in recomendadas : + similar = { + 'url': f'/static/images/{tupla[1]}', + 'name': f'{tupla[1]}', + 'similarity':f'{tupla[0]}', + + } + similares.append(similar) + + img_url=f'/static/images/{image_name}' + + return render(request, 'similar_images.html', {'similares': similares,'img':img_url,'n':n}) + + + return render(request, 'image_detail.html', {'form': form, 'images': images, 'etiqueta': etiqueta}) + + + +def images_view(request): + # Aquí puedes obtener las imágenes que quieres mostrar en la página + # desde la base de datos o cualquier otro lugar. + # En este ejemplo, suponemos que tienes una lista de diccionarios + # con información sobre las imágenes. + images = [ + { + 'url': '/static/images/1163.jpg', + 'name': 'Imagen 1', + 'link': '/images/1163.jpg', + }, + { + 'url': '/static/images/1571.jpg', + 'name': 'Imagen 2', + 'link': '/images/1571.jpg', + }, + { + 'url': '/static/images/24539.jpg', + 'name': 'Imagen 3', + 'link': '/images/24539.jpg', + }, + { + 'url': '/static/images/37802.jpg', + 'name': 'Imagen 4', + 'link': '/images/37802.jpg', + }, + { + 'url': '/static/images/59018.jpg', + 'name': 'Imagen 5', + 'link': '/images/59018.jpg', + }, + { + 'url': '/static/images/3818.jpg', + 'name': 'Imagen 6', + 'link': '/images/3818.jpg', + }, + { + 'url': '/static/images/1561.jpg', + 'name': 'Imagen 7', + 'link': '/images/1561.jpg', + }, + { + 'url': '/static/images/2334.jpg', + 'name': 'Imagen 8', + 'link': '/images/2334.jpg', + }, + + + ] + + return render(request, 'images.html', {'images': images}) + + + + + +#CODIGO PREVIO A LA OPTIMIZACION + +"""" + + + +def image_detail_original(request, image_name): + PATH="lynx/models/prueba6.pth" + + #Cargo mi modelo ya entrenado + state = torch.load(PATH,map_location=torch.device('cpu')) + + new_model =CNNModel() + new_model.load_state_dict(state) + #Obtengo la predicción de su clase + img = Image.open('lynx/static/images/'+image_name) + t_img = transformaciones(img).unsqueeze(0) + prediction = new_model.predict(t_img) + + etiqueta=classDic[prediction.item()] + print('Valor predicho: ',etiqueta ) + #Obtengo las imágenes que pertenecen a la misma clase + condicion_etiqueta = ds['target'] == prediction.item() + candidatas=ds[condicion_etiqueta] + print(candidatas) + imagenes=candidatas.image.unique() + + images = [] + for imagen in imagenes: + image = { + 'url': f'/static/images/{imagen}', + 'name': f'{imagen}', + 'link': f'/images/{imagen}', + } + images.append(image) + + form = IntegerForm(img=img, images=images) + if request.method == 'POST': form = IntegerForm(request.POST, img=img, images=images) if form.is_valid(): @@ -299,10 +435,7 @@ def image_detail(request, image_name): return render(request, 'image_detail.html', {'form': form, 'images': images, 'etiqueta': etiqueta}) - - - - +"""