Commit ·
3fd025a
1
Parent(s): e4a13e5
build structure
Browse files- .gitattributes +1 -0
- data.xlsx +3 -0
- model/pepsodent.pt +3 -0
- sys.py +56 -0
- test.ipynb +0 -0
- utils/__pycache__/data.cpython-312.pyc +0 -0
- utils/__pycache__/main.cpython-312.pyc +0 -0
- utils/__pycache__/model.cpython-312.pyc +0 -0
- utils/data.py +8 -0
- utils/main.py +55 -0
- utils/model.py +5 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
*.xlsx filter=lfs diff=lfs merge=lfs -text
|
data.xlsx
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:721c0ebb1a67f5ef2b9117ca10f1a1d2f7b4581590d565bab4ef5eefe6ab9e08
|
| 3 |
+
size 93002
|
model/pepsodent.pt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:2b719cd41b7a50fa54a3f98f4a52dcac1f93745b7868e9b82d52a61f8cad9724
|
| 3 |
+
size 195243089
|
sys.py
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import pandas as pd
|
| 3 |
+
from utils.main import main
|
| 4 |
+
import asyncio
|
| 5 |
+
|
| 6 |
+
data = pd.read_excel('data.xlsx')
|
| 7 |
+
data["Pepsodent Sensitive Expert"]=pd.NA
|
| 8 |
+
data["Pepsodent Germicheck"]=pd.NA
|
| 9 |
+
data["Shelf Talker"]=pd.NA
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
outputData = "aiGen.xlsx"
|
| 13 |
+
data["Pepsodent AI Qty."] = pd.NA
|
| 14 |
+
|
| 15 |
+
def is_valid_file(file_path):
|
| 16 |
+
return os.path.isfile(file_path)
|
| 17 |
+
|
| 18 |
+
async def det(data):
|
| 19 |
+
for index, row in data.iterrows():
|
| 20 |
+
outlet = row["Outlet code"]
|
| 21 |
+
img_path_underscore = f"img/_{row['Image No.']}"
|
| 22 |
+
img_path_no_underscore = f"img/{row['Image No.']}"
|
| 23 |
+
|
| 24 |
+
try:
|
| 25 |
+
if is_valid_file(img_path_underscore):
|
| 26 |
+
img = img_path_underscore
|
| 27 |
+
elif is_valid_file(img_path_no_underscore):
|
| 28 |
+
img = img_path_no_underscore
|
| 29 |
+
else:
|
| 30 |
+
continue # Skip to the next image if both paths are invalid
|
| 31 |
+
|
| 32 |
+
print(img)
|
| 33 |
+
result = await main(img)
|
| 34 |
+
for name,count in result.items():
|
| 35 |
+
data.at[index,"Shelf Talker"]="No"
|
| 36 |
+
if name=="Pepsodent Germicheck":
|
| 37 |
+
data.at[index, "Pepsodent Germicheck"] = result["Pepsodent Germicheck"]
|
| 38 |
+
|
| 39 |
+
elif name=="Pepsodent Sensitive Expert":
|
| 40 |
+
data.at[index, "Pepsodent Sensitive Expert"] = result["Pepsodent Sensitive Expert"]
|
| 41 |
+
|
| 42 |
+
elif name=="Pepsodent Shelf Talker":
|
| 43 |
+
data.at[index,"Shelf Talker"]="Yes"
|
| 44 |
+
print(result)
|
| 45 |
+
|
| 46 |
+
except Exception as e:
|
| 47 |
+
print(f"Error processing image {row['Image No.']}: {e}")
|
| 48 |
+
continue # Continue to the next image if an error occurs
|
| 49 |
+
|
| 50 |
+
async def main_async():
|
| 51 |
+
await det(data)
|
| 52 |
+
data.to_excel(outputData, index=False)
|
| 53 |
+
|
| 54 |
+
# Entry point for the script
|
| 55 |
+
if __name__ == "__main__":
|
| 56 |
+
asyncio.run(main_async())
|
test.ipynb
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
utils/__pycache__/data.cpython-312.pyc
ADDED
|
Binary file (332 Bytes). View file
|
|
|
utils/__pycache__/main.cpython-312.pyc
ADDED
|
Binary file (2.07 kB). View file
|
|
|
utils/__pycache__/model.cpython-312.pyc
ADDED
|
Binary file (354 Bytes). View file
|
|
|
utils/data.py
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pepsodent_qpds_data = {
|
| 2 |
+
"pepsodent_germicheck":"Pepsodent Germicheck",
|
| 3 |
+
"pepsodent_sensitive_expert":"Pepsodent Sensitive Expert",
|
| 4 |
+
"pepsodent_shelf_talker":"Pepsodent Shelf Talker",
|
| 5 |
+
}
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
# pepsodent_qpds_data = {"PEPSODENT":"Pepsodent"}
|
utils/main.py
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
import pandas as pd
|
| 3 |
+
from PIL import Image
|
| 4 |
+
from .model import model
|
| 5 |
+
from .data import pepsodent_qpds_data
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
async def detection(model, img_content, confidence):
|
| 13 |
+
try:
|
| 14 |
+
img = Image.open(img_content)
|
| 15 |
+
result = model(source=img, device=0, conf=confidence)
|
| 16 |
+
detection = {}
|
| 17 |
+
data = json.loads(result[0].tojson())
|
| 18 |
+
if not result or not data:
|
| 19 |
+
return {}
|
| 20 |
+
else:
|
| 21 |
+
name_counts = {}
|
| 22 |
+
for item in data:
|
| 23 |
+
name = item['name']
|
| 24 |
+
if name in name_counts:
|
| 25 |
+
name_counts[name] += 1
|
| 26 |
+
else:
|
| 27 |
+
name_counts[name] = 1
|
| 28 |
+
detection.update(name_counts)
|
| 29 |
+
|
| 30 |
+
return detection
|
| 31 |
+
except Exception as e:
|
| 32 |
+
return {}
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
async def format_result(convertData,resData):
|
| 36 |
+
try:
|
| 37 |
+
result = {}
|
| 38 |
+
for aiName,sysName in convertData.items():
|
| 39 |
+
if aiName in resData:
|
| 40 |
+
result.update({sysName:resData[aiName]})
|
| 41 |
+
return result
|
| 42 |
+
except Exception as e:
|
| 43 |
+
pass
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
async def main(img):
|
| 49 |
+
try:
|
| 50 |
+
result = await detection(model,img,0.3)
|
| 51 |
+
formattedResult = await format_result(pepsodent_qpds_data,result)
|
| 52 |
+
|
| 53 |
+
return formattedResult
|
| 54 |
+
except Exception as e:
|
| 55 |
+
pass
|
utils/model.py
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from ultralytics import YOLO
|
| 2 |
+
|
| 3 |
+
model_init= YOLO('model/pepsodent.pt').cuda()
|
| 4 |
+
|
| 5 |
+
model = model_init.to(device=0)
|