"Typeerror: Only size-1 arrays can be converted to Python scalars" hatası

Playizm

Kilopat
Katılım
26 Haziran 2019
Mesajlar
787
Çözümler
10
Merhaba obje tanmaya girmek istedim bunun için YouTube baktım bir video buldum Türk fakat her şeyi bitirdim şu hatayı alıyorum.
TypeError: only size-1 arrays can be converted to Python scalars
Kodum şu:

İmport CV2.
İmport numpy as NP.

İmg = cv2.imread("C:/Users/Rehabilite/yolo/office.jpg")
#Print (img)

İMG_WIDTH = img. Shape [1]
İMG_HEIGHT = img. Shape [0]

İMG_BLOB = cv2.dnn. Blobfromımage(img, 1/255, (416, 416),swaprb = true)
Labels =["person", "bicycle", "car", "motorcycle", "airplane", "bus", "train", "truck", "boat",
"trafficlight", "firehydrant", "stopsign", "parkingmeter", "bench", "bird", "cat",
"dog", "horse", "sheep", "cow", "elephant", "bear", "zebra", "giraffe", "backpack",
"umbrella", "handbag", "tie", "suitcase", "frisbee", "skis", "snowboard", "sportsball",
"kite", "baseballbat", "baseballglove", "skateboard", "surfboard", "tennisracket",
"bottle", "wineglass", "cup", "fork", "knife", "spoon", "bowl", "banana", "apple",
"sandwich", "orange", "broccoli", "carrot", "hotdog", "pizza", "donut", "cake", "chair",
"sofa", "pottedplant", "bed", "diningtable", "toilet", "tvmonitor", "laptop", "mouse",
"remote", "keyboard", "cellphone", "microwave", "oven", "toaster", "sink", "refrigerator",
"book", "clock", "vase", "scissors", "teddybear", "hairdrier", "toothbrush"]

Colors = ["255,255,0","0,255,0","0,255,255","255,0,255""0,0,255"]
Colors = [np.array(color.split(",")).astype("int") for color in colors]
Colors = np. Array(colors)
Colors = np. Tile (colors,(20, 1))

Model = cv2.dnn.readNetFromDarknet("C:/Users/Rehabilite/yolo/model/yolov3.cfg","C:/Users/Rehabilite/yolo/model/yolov3.weights")
Layers = model.getLayerNames()
OUTPUT_LAYER =[layers[layer[0]-1] for layer in model.getUnconnectedOutLayers() ]

Model. Setınput (img_blob)

DETECTION_LAYERS = model. Forward(output_layer)

For DETECTION_LAYER in DETECTION_LAYERS:
For OBJECT_DETECTION in DETECTION_LAYER:
Scores = OBJECT_DETECTION [5:]
PREDICTED_ID = np. Argmax(scores)
Confidence = scores[predicted_id]

If confidence > 0.30:

Label = labels [predicted_id]
BOUNDING_BOX = OBJECT_DETECTION[0:4] * np. Array ([img_width, img_height, img_width, img_height])
(Box_center_x, BOX_CENTER_Y, BOX_WIDTH, BOX_HEIGHT) = BOUNDING_BOX. Astype("int")

Start_x = int(box_center_x - (box_width/2))
Start_y = int (box_center_y - (box_height/2))

End_x = start_x + BOX_WIDTH.
End_y = start_y + BOX_HEIGHT.

BOX_COLOR = colors[predicted_id]
BOX_COLOR = [int(each) for each in box_color]
Cv2. rectangle(img, (start_x, start_y), (end_x, end_y), BOX_COLOR, 2)
Cv2.puttext(img, label,(start_x, stART_Y-20). Cv2. FONT_HERSHEY_SIMPLEX,0.5. BOX_COLOR, 1)
Cv2.imshow("tespit ekranı", img)
 
Son düzenleyen: Moderatör:
Kod görünmüyor.
yenimsin üzerine tıkla knk
konu günceldir.
Konu çözülmüştür videoyu yanlışıkla numpade elim değmiş herhalde baya bir ilerletmişim
yanlış alarm herşeyi yaptım ama hala aynı hatayı veriyor
 
Son düzenleme:
Kod:
Model = cv2.dnn.readNetFromDarknet("C:/Users/Rehabilite/yolo/model/yolov3.cfg","C:/Users/Rehabilite/yolo/model/yolov3.weights")

Burada bir dosya yolu var. O kik dosya ve orada geçen dosya yolu ve kullanıcı adı senin bilgisayarında mevcut değil. (Rehabilite senin kullanıcı adın değilse)
 
Evet rehabailite benim kullanıcı adım değişik bi isim koyuyım dedim
Ayrıca ordaki şeyler doğru
Çalıştırdığımda
Python:
C:\Users\Rehabilite\yolo\nesne_tanıma.py:31: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray
  colors = np.array(colors)
Traceback (most recent call last):

  File "C:\Users\Rehabilite\yolo\nesne_tanıma.py", line 93, in <module>
    box_color = [int(each) for each in box_color]

  File "C:\Users\Rehabilite\yolo\nesne_tanıma.py", line 93, in <listcomp>
    box_color = [int(each) for each in box_color]

TypeError: only size-1 arrays can be converted to Python scalars
 
Hata diziler ile ilgili. Python saymaya bir'den değil, sıfırdan başlıyor. Belki fazladan bir veri eklenmiş olabilir.
 
Bu siteyi kullanmak için çerezler gereklidir. Siteyi kullanmaya devam etmek için çerezleri kabul etmelisiniz. Daha Fazlasını Öğren.…