Как исправить TypeError: аргумент int() должен быть строкой, байтовым объектом или числом, а не «NoneType»?

Моя цель — транслировать видео обнаружения объектов с камеры Raspberry Pi в UDP. Я делаю это на Nvidia Jetson Nano (Ubuntu 18.04). Я использую gstreamer для захвата видео. Мне нужно кодировать видео с помощью h264. Пиксельный формат камеры — «RG10». Я пробовал другой конвейер для захвата видео, но ничего не изменилось. Я думаю, проблема в захвате видео. Я не мог понять. Я новичок. Так что мне нужна помощь.

Вот код:


import os
import numpy as np
import tensorflow as tf
import sys

sys.path.append('/usr/local/lib/python3.6/dist-packages')
import cv2 as cv2

from utils import label_map_util
from utils import visualization_utils as vis_util

MODEL_NAME = 'inference_graph'
CWD_PATH = os.getcwd()
PATH_TO_CKPT = os.path.join(CWD_PATH,MODEL_NAME,'frozen_inference_graph.pb')
PATH_TO_LABELS = os.path.join(CWD_PATH,'training','labelmap.pbtxt')
NUM_CLASSES = 1

label_map = label_map_util.load_labelmap(PATH_TO_LABELS)
categories = label_map_util.convert_label_map_to_categories(label_map, max_num_classes=NUM_CLASSES, use_display_name=True)
category_index = label_map_util.create_category_index(categories)

detection_graph = tf.Graph()
with detection_graph.as_default():
    od_graph_def = tf.GraphDef()
    with tf.gfile.GFile(PATH_TO_CKPT, 'rb') as fid:
        serialized_graph = fid.read()
        od_graph_def.ParseFromString(serialized_graph)
        tf.import_graph_def(od_graph_def, name='')
    sess = tf.Session(graph=detection_graph)

image_tensor = detection_graph.get_tensor_by_name('image_tensor:0')

detection_boxes = detection_graph.get_tensor_by_name('detection_boxes:0')
detection_scores = detection_graph.get_tensor_by_name('detection_scores:0')
detection_classes = detection_graph.get_tensor_by_name('detection_classes:0')
num_detections = detection_graph.get_tensor_by_name('num_detections:0')

writer = cv2.VideoWriter(" appsrc name=appsrc_element block=true ! video/x-raw,format=RGB,width=320,height=240,framerate=30/1 ! identity check-imperfect-timestamp=true ! videoconvert ! x264enc ! video/x-h264,profile=\"high-4:4:4\ ! rtph264pay  ! udpsink host= 192.168.1.49 port=5000 ",cv2.CAP_GSTREAMER,0, 20, (320,240), True) # Write frames here after processing


video = cv2.VideoCapture('nvarguscamerasrc ! image/jpg,width=1280,height=720,type=video,framerate=30/1 ! videoscale ! videoconvert ! x264enc tune=zerolatency ! rtph264pay ! appsink ', cv2.CAP_GSTREAMER)
ret = video.set(3,1280)
ret = video.set(4,720)

while(True):


    ret, frame = video.read()   
    frame_expanded = np.expand_dims(frame, axis=0)


    (boxes, scores, classes, num) = sess.run(
        [detection_boxes, detection_scores, detection_classes, num_detections],
        feed_dict={image_tensor: frame_expanded})

    vis_util.visualize_boxes_and_labels_on_image_array(
        frame,
        np.squeeze(boxes),
        np.squeeze(classes).astype(np.int32),
        np.squeeze(scores),
        category_index,
        use_normalized_coordinates=True,
        line_thickness=8,
        min_score_thresh=0.85)

    w_size = cv2.getWindowImageRect('frame')

    print(w_size)
    cv2.rectangle(frame,(int(int(w_size[2])*0.25) ,int(int(w_size[3])*0.10)),(int(int(w_size[2])*0.75),int(int(w_size[3])*0.90)),(0,255,0),3)

    writer.write(frame) 


    if cv2.waitKey(1) == ord('q'):
        break

video.release()
writer.release()
cv2.destroyAllWindows()

Это ошибка вывода:

  _np_qint8 = np.dtype([("qint8", np.int8, 1)])
/home/berfu/.virtualenvs/deep_learning/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:527: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint8 = np.dtype([("quint8", np.uint8, 1)])
/home/berfu/.virtualenvs/deep_learning/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:528: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint16 = np.dtype([("qint16", np.int16, 1)])
/home/berfu/.virtualenvs/deep_learning/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:529: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint16 = np.dtype([("quint16", np.uint16, 1)])
/home/berfu/.virtualenvs/deep_learning/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:530: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint32 = np.dtype([("qint32", np.int32, 1)])
/home/berfu/.virtualenvs/deep_learning/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:535: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  np_resource = np.dtype([("resource", np.ubyte, 1)])
2019-09-07 02:26:33.800624: W tensorflow/core/platform/profile_utils/cpu_utils.cc:98] Failed to find bogomips in /proc/cpuinfo; cannot determine CPU frequency
2019-09-07 02:26:33.804717: I tensorflow/compiler/xla/service/service.cc:161] XLA service 0x2816fdf0 executing computations on platform Host. Devices:
2019-09-07 02:26:33.805320: I tensorflow/compiler/xla/service/service.cc:168]   StreamExecutor device (0): <undefined>, <undefined>
2019-09-07 02:26:33.895575: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:965] ARM64 does not support NUMA - returning NUMA node zero
2019-09-07 02:26:33.895923: I tensorflow/compiler/xla/service/service.cc:161] XLA service 0x24aca990 executing computations on platform CUDA. Devices:
2019-09-07 02:26:33.895984: I tensorflow/compiler/xla/service/service.cc:168]   StreamExecutor device (0): NVIDIA Tegra X1, Compute Capability 5.3
2019-09-07 02:26:33.896452: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1433] Found device 0 with properties: 
name: NVIDIA Tegra X1 major: 5 minor: 3 memoryClockRate(GHz): 0.9216
pciBusID: 0000:00:00.0
totalMemory: 3.86GiB freeMemory: 272.39MiB
2019-09-07 02:26:33.896515: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1512] Adding visible gpu devices: 0
2019-09-07 02:26:35.073590: I tensorflow/core/common_runtime/gpu/gpu_device.cc:984] Device interconnect StreamExecutor with strength 1 edge matrix:
2019-09-07 02:26:35.073769: I tensorflow/core/common_runtime/gpu/gpu_device.cc:990]      0 
2019-09-07 02:26:35.073809: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1003] 0:   N 
2019-09-07 02:26:35.074121: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1115] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 42 MB memory) -> physical GPU (device: 0, name: NVIDIA Tegra X1, pci bus id: 0000:00:00.0, compute capability: 5.3)
GST_ARGUS: Creating output stream
CONSUMER: Waiting until producer is connected...
GST_ARGUS: Available Sensor modes :
GST_ARGUS: 3280 x 2464 FR = 21.000000 fps Duration = 47619048 ; Analog Gain range min 1.000000, max 10.625000; Exposure Range min 13000, max 683709000;

GST_ARGUS: 3280 x 1848 FR = 28.000001 fps Duration = 35714284 ; Analog Gain range min 1.000000, max 10.625000; Exposure Range min 13000, max 683709000;

GST_ARGUS: 1920 x 1080 FR = 29.999999 fps Duration = 33333334 ; Analog Gain range min 1.000000, max 10.625000; Exposure Range min 13000, max 683709000;

GST_ARGUS: 1280 x 720 FR = 59.999999 fps Duration = 16666667 ; Analog Gain range min 1.000000, max 10.625000; Exposure Range min 13000, max 683709000;

GST_ARGUS: 1280 x 720 FR = 120.000005 fps Duration = 8333333 ; Analog Gain range min 1.000000, max 10.625000; Exposure Range min 13000, max 683709000;

GST_ARGUS: Running with following settings:
   Camera index = 0 
   Camera mode  = 2 
   Output Stream W = 1920 H = 1080 
   seconds to Run    = 0 
   Frame Rate = 29.999999 
GST_ARGUS: PowerService: requested_clock_Hz=13608000
GST_ARGUS: Setup Complete, Starting captures for 0 seconds
GST_ARGUS: Starting repeat capture requests.
CONSUMER: Producer has connected; continuing.
GST_ARGUS: Cleaning up
GST_ARGUS: 
PowerServiceHwVic::cleanupResources
CONSUMER: Done Success
GST_ARGUS: Done Success
<class 'NoneType'>
Traceback (most recent call last):
  File "webcam.py", line 68, in <module>
    feed_dict={image_tensor: frame_expanded})
  File "/home/berfu/.virtualenvs/deep_learning/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 929, in run
    run_metadata_ptr)
  File "/home/berfu/.virtualenvs/deep_learning/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1121, in _run
    np_val = np.asarray(subfeed_val, dtype=subfeed_dtype)
  File "/home/berfu/.virtualenvs/deep_learning/lib/python3.6/site-packages/numpy/core/_asarray.py", line 85, in asarray
    return array(a, dtype, copy=False, order=order)
TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'

Спасибо за помощь


person Yunus Berfu Özcan    schedule 06.09.2019    source источник


Ответы (1)


Значения в feed_dict должны быть преобразованы в массив numpy — похоже, что frame_expanded может содержать None. Попробуйте распечатать значения feed_dict, чтобы убедиться, что они содержат достоверные данные.

person IronMan    schedule 07.09.2019
comment
Я не мог напечатать feed_dict, но frame равно ```Нет`` - person Yunus Berfu Özcan; 07.09.2019
comment
Это объясняет - video.read() вернул None, потому что не смог захватить кадр. (Если кадры не были захвачены (камера была отключена или в видеофайле больше нет кадров), методы возвращают false, а функции возвращают указатель NULL.) - person IronMan; 07.09.2019