Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- set -euo pipefail
- IMGDIR="imagenes"
- if [ ! -d "$IMGDIR" ]; then
- echo "no se encontro el directorio '$IMGDIR'"
- echo "crea la carpeta y llamala imagenes"
- exit 1
- fi
- # haces los json si no existen
- [ -f etiquetas.json ] || echo "{}" > etiquetas.json
- [ -f imagenes.json ] || echo "{}" > imagenes.json
- # recorre cada archivo de imagen en el directorio
- for img in "${IMGDIR}"/*.{jpg,jpeg,png}; do
- [ -f "$img" ] || continue
- filename=$(basename "$img")
- echo "Procesando $filename …"
- # el yolo ese
- yolo_out=$(yolo predict source="$img" 2>&1)
- info_line=$(printf "%s\n" "$yolo_out" | grep 'image 1/1')
- if echo "$info_line" | grep -q "(no detections)"; then
- tags="no_detections"
- else
- raw_tags=$(printf "%s\n" "$info_line" \
- | sed -E 's/.*[0-9]+x[0-9]+ (.*): [0-9]+.*$/\1/')
- tags=$(printf "%s\n" "$raw_tags" | sed -E 's/[0-9]+ //g')
- fi
- # agregas la ruta al json para cada una
- IFS=',' read -ra TAG_ARR <<< "$tags"
- for tag in "${TAG_ARR[@]}"; do
- tag=$(echo "$tag" | xargs) # cortas
- jq --arg t "$tag" --arg p "${IMGDIR}/${filename}" \
- '.[$t] = (.[$t] // []) + [$p]' \
- etiquetas.json > etiquetas.tmp.json \
- && mv etiquetas.tmp.json etiquetas.json
- done
- # el moondream ese
- desc=$(ollama run moondream "{'content':'Describe me this image','images':'$img'}" 2>&1 | tail -n1)
- jq --arg k "$filename" --arg d "$desc" \
- '.[$k] = $d' \
- imagenes.json > imagenes.tmp.json \
- && mv imagenes.tmp.json imagenes.json
- done
- echo "ok funciona todo"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement