add cats
Gitea Actions Demo / build_and_push (push) Failing after 1m19s
Details
Gitea Actions Demo / build_and_push (push) Failing after 1m19s
Details
This commit is contained in:
parent
b8dc67edf7
commit
bff80715b6
|
|
@ -35,11 +35,16 @@ def load_model(model_path, device="cpu"):
|
||||||
with open("server/meta/images.json", "r") as f:
|
with open("server/meta/images.json", "r") as f:
|
||||||
IMAGES = json.loads(f.read())
|
IMAGES = json.loads(f.read())
|
||||||
|
|
||||||
MODEL = load_model("server/models/dogs_model.pth")
|
DOG_MODEL = load_model("server/models/dogs_model.pth")
|
||||||
|
CAT_MODEL = load_model("server/models/cats_model.pth")
|
||||||
|
|
||||||
with open("server/meta/labels_dogs.json", "r") as f:
|
with open("server/meta/labels_dogs.json", "r") as f:
|
||||||
data_labels = f.read()
|
data_labels = f.read()
|
||||||
labels_dict = json.loads(data_labels)
|
labels_dogs = json.loads(data_labels)
|
||||||
|
|
||||||
|
with open("server/meta/labels_cats.json", "r") as f:
|
||||||
|
data_labels = f.read()
|
||||||
|
labels_cats = json.loads(data_labels)
|
||||||
|
|
||||||
|
|
||||||
def predict_image(image, model, device="cuda") -> list[tuple]:
|
def predict_image(image, model, device="cuda") -> list[tuple]:
|
||||||
|
|
@ -71,18 +76,18 @@ class BeerdsController(Controller):
|
||||||
path = "/beerds"
|
path = "/beerds"
|
||||||
|
|
||||||
@post("/dogs")
|
@post("/dogs")
|
||||||
async def beerds(
|
async def beerds_dogs(
|
||||||
self, data: UploadFile = Body(media_type=RequestEncodingType.MULTI_PART)
|
self, data: UploadFile = Body(media_type=RequestEncodingType.MULTI_PART)
|
||||||
) -> dict:
|
) -> dict:
|
||||||
body = await data.read()
|
body = await data.read()
|
||||||
|
|
||||||
img_file = Image.open(io.BytesIO(body))
|
img_file = Image.open(io.BytesIO(body))
|
||||||
predicted_data = predict_image(img_file, MODEL, "cpu")
|
predicted_data = predict_image(img_file, DOG_MODEL, "cpu")
|
||||||
results = {}
|
results = {}
|
||||||
images = []
|
images = []
|
||||||
for d in predicted_data:
|
for d in predicted_data:
|
||||||
predicted_idx, probabilities = d
|
predicted_idx, probabilities = d
|
||||||
predicted_label = labels_dict[str(predicted_idx)]
|
predicted_label = labels_dogs[str(predicted_idx)]
|
||||||
name = predicted_label.replace("_", " ")
|
name = predicted_label.replace("_", " ")
|
||||||
images.append({"name": name, "url": IMAGES[name]})
|
images.append({"name": name, "url": IMAGES[name]})
|
||||||
results[float(probabilities[0])] = name
|
results[float(probabilities[0])] = name
|
||||||
|
|
@ -91,6 +96,24 @@ class BeerdsController(Controller):
|
||||||
"images": images,
|
"images": images,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@post("/cats")
|
||||||
|
async def beerds_cats(
|
||||||
|
self, data: UploadFile = Body(media_type=RequestEncodingType.MULTI_PART)
|
||||||
|
) -> dict:
|
||||||
|
body = await data.read()
|
||||||
|
|
||||||
|
img_file = Image.open(io.BytesIO(body))
|
||||||
|
predicted_data = predict_image(img_file, CAT_MODEL, "cpu")
|
||||||
|
results = {}
|
||||||
|
for d in predicted_data:
|
||||||
|
predicted_idx, probabilities = d
|
||||||
|
predicted_label = labels_cats[str(predicted_idx)]
|
||||||
|
results[float(probabilities[0])] = predicted_label
|
||||||
|
return {
|
||||||
|
"results": results,
|
||||||
|
"images": [],
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class BaseController(Controller):
|
class BaseController(Controller):
|
||||||
path = "/"
|
path = "/"
|
||||||
|
|
@ -99,6 +122,10 @@ class BaseController(Controller):
|
||||||
async def main(self) -> Template:
|
async def main(self) -> Template:
|
||||||
return Template(name="index.html")
|
return Template(name="index.html")
|
||||||
|
|
||||||
|
@get("/cats")
|
||||||
|
async def cats(self) -> Template:
|
||||||
|
return Template(name="cats.html")
|
||||||
|
|
||||||
@get("/sitemap.xml", media_type=MediaType.XML)
|
@get("/sitemap.xml", media_type=MediaType.XML)
|
||||||
async def sitemaps(self) -> bytes:
|
async def sitemaps(self) -> bytes:
|
||||||
return """<?xml version="1.0" encoding="UTF-8"?>
|
return """<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
@ -112,7 +139,11 @@ class BaseController(Controller):
|
||||||
|
|
||||||
<url>
|
<url>
|
||||||
<loc>https://xn-----6kcp3cadbabfh8a0a.xn--p1ai/</loc>
|
<loc>https://xn-----6kcp3cadbabfh8a0a.xn--p1ai/</loc>
|
||||||
<lastmod>2023-05-01T19:01:03+00:00</lastmod>
|
<lastmod>2025-04-21T19:01:03+00:00</lastmod>
|
||||||
|
</url>
|
||||||
|
<url>
|
||||||
|
<loc>https://xn-----6kcp3cadbabfh8a0a.xn--p1ai/cats</loc>
|
||||||
|
<lastmod>2025-04-21T19:01:03+00:00</lastmod>
|
||||||
</url>
|
</url>
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,13 @@
|
||||||
|
|
||||||
let urlCreator = window.URL || window.webkitURL;
|
let urlCreator = window.URL || window.webkitURL;
|
||||||
|
|
||||||
async function SavePhoto() {
|
async function SavePhoto(self) {
|
||||||
document.getElementById("result").innerHTML = "";
|
document.getElementById("result").innerHTML = "";
|
||||||
let photo = document.getElementById("file-input").files[0];
|
let photo = document.getElementById("file-input").files[0];
|
||||||
let formData = new FormData();
|
let formData = new FormData();
|
||||||
// TODO: пройтись по всем результатм - если совпадают дважды - поднять вверх
|
// TODO: пройтись по всем результатм - если совпадают дважды - поднять вверх
|
||||||
formData.append("f", photo);
|
formData.append("f", photo);
|
||||||
let response = await fetch('/beerds/dogs', { method: "POST", body: formData });
|
let response = await fetch(self.action, { method: "POST", body: formData });
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
let json = await response.json();
|
let json = await response.json();
|
||||||
let text = "<h3 class='image-results'>Результаты</h3>";
|
let text = "<h3 class='image-results'>Результаты</h3>";
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,50 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="ru">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="yandex-verification" content="2d4efced567f0f7f" />
|
||||||
|
<meta name="google-site-verification" content="gKPSnPZ1ULUF9amD0vw_JQqkS5GLqc937UxayaN_s-I" />
|
||||||
|
<meta name="description" content="Опередление породы собаки по фото. Определение породы происходит при помощи нейронной сети - точность опеределения составляет 60%." />
|
||||||
|
<link rel="icon" type="image/x-icon" href="static/favicon.ico">
|
||||||
|
<title>Определение породы кошки по фото</title>
|
||||||
|
<link rel="stylesheet" href="static/styles.css">
|
||||||
|
<!-- Yandex.Metrika counter -->
|
||||||
|
<script type="text/javascript" >
|
||||||
|
(function(m,e,t,r,i,k,a){m[i]=m[i]||function(){(m[i].a=m[i].a||[]).push(arguments)};
|
||||||
|
m[i].l=1*new Date();
|
||||||
|
for (var j = 0; j < document.scripts.length; j++) {if (document.scripts[j].src === r) { return; }}
|
||||||
|
k=e.createElement(t),a=e.getElementsByTagName(t)[0],k.async=1,k.src=r,a.parentNode.insertBefore(k,a)})
|
||||||
|
(window, document, "script", "https://mc.yandex.ru/metrika/tag.js", "ym");
|
||||||
|
|
||||||
|
ym(93420354, "init", {
|
||||||
|
clickmap:true,
|
||||||
|
trackLinks:true,
|
||||||
|
accurateTrackBounce:true
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
<noscript><div><img src="https://mc.yandex.ru/watch/93420354" style="position:absolute; left:-9999px;" alt="" /></div></noscript>
|
||||||
|
<!-- /Yandex.Metrika counter -->
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<section id="main">
|
||||||
|
<h1>Определить породу кошки по фото</h1>
|
||||||
|
<p>Узнать породу <a href = "/">Собаки</a></p>
|
||||||
|
<p>Загрузите фото, чтобы опеределить породу собаки или щенка. Если порода смешанная (или порода определена неточно), после загрузки будет показана вероятность породы животного.</p>
|
||||||
|
<p>Определение породы происходит при помощи нейронной сети - точность опеределения составляет 60%, сеть обучена на 65 породах. Если на фото будет неизвестная порода или не кошка - сеть не сможет правильно опеределить, что это.</p>
|
||||||
|
<p>Для распознования все фото отправляются на сервер, но там не сохраняются</p>
|
||||||
|
<form enctype="multipart/form-data" method="post" action="/beerds/cats" onsubmit="SavePhoto(this);return false">
|
||||||
|
<p><input type="file" name="f" id="file-input">
|
||||||
|
<input type="submit" value="Определить"></p>
|
||||||
|
</form>
|
||||||
|
<div>
|
||||||
|
<div id="upload-image">
|
||||||
|
<div id="upload-image-text"></div>
|
||||||
|
<img id="image" style="max-width: 200px;"/>
|
||||||
|
</div>
|
||||||
|
<div id="result"></div>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</section>
|
||||||
|
<script src="static/scripts.js"></script>
|
||||||
|
|
||||||
|
</html>
|
||||||
|
|
@ -28,10 +28,11 @@
|
||||||
<body>
|
<body>
|
||||||
<section id="main">
|
<section id="main">
|
||||||
<h1>Определить породу собаки по фото</h1>
|
<h1>Определить породу собаки по фото</h1>
|
||||||
|
<p>Узнать породу <a href = "/cats">Кошки</a></p>
|
||||||
<p>Загрузите фото, чтобы опеределить породу собаки или щенка. Если порода смешанная (или порода определена неточно), после загрузки будет показана вероятность породы животного.</p>
|
<p>Загрузите фото, чтобы опеределить породу собаки или щенка. Если порода смешанная (или порода определена неточно), после загрузки будет показана вероятность породы животного.</p>
|
||||||
<p>Определение породы происходит при помощи нейронной сети - точность опеределения составляет 60%, сеть обучена на <a href="https://vk.com/albums-220240483" target="_blank">125 породах</a>. Если на фото будет неизвестная порода или не собака - сеть не сможет правильно опеределить, что это.</p>
|
<p>Определение породы происходит при помощи нейронной сети - точность опеределения составляет 60%, сеть обучена на <a href="https://vk.com/albums-220240483" target="_blank">125 породах</a>. Если на фото будет неизвестная порода или не собака - сеть не сможет правильно опеределить, что это.</p>
|
||||||
<p>Для распознования все фото отправляются на сервер, но там не сохраняются</p>
|
<p>Для распознования все фото отправляются на сервер, но там не сохраняются</p>
|
||||||
<form enctype="multipart/form-data" method="post" action="/beerds/dogs" onsubmit="SavePhoto();return false">
|
<form enctype="multipart/form-data" method="post" action="/beerds/dogs" onsubmit="SavePhoto(this);return false">
|
||||||
<p><input type="file" name="f" id="file-input">
|
<p><input type="file" name="f" id="file-input">
|
||||||
<input type="submit" value="Определить"></p>
|
<input type="submit" value="Определить"></p>
|
||||||
</form>
|
</form>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue