You need to enable JavaScript to run this app.

Ana içeriğe geç

TensorFlow ile Nesne Tanıma (Önceden Eğitilmiş Model)

TensorFlow ile Nesne Tanıma (Önceden Eğitilmiş Model)

Kodlar.TR Müdavim
TensorFlow ile Nesne Tanıma (Önceden Eğitilmiş Model)
TensorFlow ile Nesne Tanıma (Önceden Eğitilmiş Model)

TensorFlow Hub'dan önceden eğitilmiş bir model kullanarak nesne tanıma yapabilirsiniz. Aşağıdaki örnek, bir görüntüdeki nesneleri tanır ve etiketler.
python

Kopyala
Kod:
import tensorflow as tf
import tensorflow_hub as hub
import numpy as np
import cv2

# Modeli TensorFlow Hub'dan yükle (EfficientDet)
model = hub.load('https://tfhub.dev/tensorflow/efficientdet/d4/1')

# Görüntüyü oku ve hazırla
image = cv2.imread('nesne_resmi.jpg')
image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
image_tensor = tf.convert_to_tensor(image_rgb, dtype=tf.uint8)[tf.newaxis, ...]

# Modeli çalıştır
results = model(image_tensor)

# Sonuçları işle
boxes = results['detection_boxes'].numpy()[0]
scores = results['detection_scores'].numpy()[0]
classes = results['detection_classes'].numpy()[0].astype(int)

# Tespit edilen nesneleri çiz
for i in range(len(scores)):
    if scores[i] > 0.5:  # Güven skoru %50'den büyükse
        box = boxes[i]
        y1, x1, y2, x2 = (box * [image.shape[0], image.shape[1], image.shape[0], image.shape[1]]).astype(int)
        cv2.rectangle(image, (x1, y1), (x2, y2), (0, 255, 0), 2)
        cv2.putText(image, f'Class {classes[i]}: {scores[i]:.2f}', (x1, y1-10),
                    cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2)

# Sonucu göster
cv2.imshow('Nesne Tespiti', image)
cv2.waitKey(0)
cv2.destroyAllWindows()


Gereksinimler:
  • pip install tensorflow tensorflow-hub opencv-python
  • nesne_resmi.jpg adında bir görüntü dosyası.
  • Bu kod, EfficientDet modelini kullanarak görüntüdeki nesneleri tespit eder ve etiketler.