0

I've just been following the Yeah-World tutorial and have done all the things it said, except I changed the code in record.py so it can use a standard USB webcam:

cap = cv2.VideoCapture(0)
frames = []
started = time()
while time() - started < seconds:
     frame = cap.read()
     frames.append(frame)

The only thing I changed was the loop where it records frame by frame, I removed the camera dependencies from everything because it pointed towards Picamera, because I don't have a Picamera currently. After that I tested record.py and it worked! When I tried to train a model based on the standard yeah, sitting, and random, I got the error from pinet.py:

2020-04-13 15:37:00.067761: E tensorflow/core/platform/hadoop/hadoop_file_system.cc:132] HadoopFileSystem load error: libhdfs.so: cannot open shared object file: No such file or directory
Loading tensorflow feature extractor...
WARNING:tensorflow:From /home/pi/ML-examples/yeah-world/pinet.py:28: The name tf.gfile.GFile is deprecated. Please use tf.io.gfile.GFile instead.

WARNING:tensorflow:From /home/pi/ML-examples/yeah-world/pinet.py:29: The name tf.GraphDef is deprecated. Please use tf.compat.v1.GraphDef instead.

WARNING:tensorflow:From /home/pi/ML-examples/yeah-world/pinet.py:37: The name tf.Session is deprecated. Please use tf.compat.v1.Session instead.

Loading example/yeahTraceback (most recent call last):
File "train.py", line 101, in
main()
File "train.py", line 55, in main
features = [feature_extractor.features(f) for f in x]
File "train.py", line 55, in
features = [feature_extractor.features(f) for f in x]
File "/home/pi/ML-examples/yeah-world/pinet.py", line 45, in features
preprocessed = ((np.array(image, dtype=np.float32) / 255.) - 0.5) * 2.
ValueError: setting an array element with a sequence.

I looked up the error and it said that it was trying to force an uneven multidimensional array into something? I don't know if it's messed up because my webcam may be giving it the wrong format of data, or if I don't have the right version of NumPy installed. Please forgive me if I did something wrong, this is my first time posting a question/issue

I have a Rasberry Pi 3B+ running Raspbian GNU/Linux 10 (buster)

The output of print(cap.read()):

Recording [ 10 frames,   0s left ](True, array([[[ 34,  38,  57],
        [ 33,  36,  57],
        [ 34,  34,  58],
        ...,
        [ 42,  41,  73],
        [ 40,  42,  73],
        [ 41,  42,  76]],

       [[ 31,  37,  56],
        [ 31,  36,  57],
        [ 32,  34,  58],
        ...,
        [ 39,  41,  71],
        [ 39,  43,  72],
        [ 40,  43,  74]],

       [[ 25,  38,  54],
        [ 27,  37,  55],
        [ 27,  36,  56],
        ...,
        [ 35,  42,  67],
        [ 34,  43,  70],
        [ 36,  45,  72]],

       ...,

       [[ 19,  10,  43],
        [ 20,  12,  43],
        [ 20,  13,  40],
        ...,
        [208, 225, 234],
        [201, 219, 230],
        [196, 214, 225]],

       [[ 21,  13,  50],
        [ 21,  14,  49],
        [ 23,  15,  46],
        ...,
        [210, 225, 234],
        [205, 222, 231],
        [202, 219, 228]],

       [[ 23,  15,  55],
        [ 23,  15,  52],
        [ 23,  16,  49],
        ...,
        [210, 223, 231],
        [207, 223, 230],
        [206, 222, 229]]], dtype=uint8))
  • Whats the output of frame? – Jakob Apr 14 at 17:59
  • I'm sorry, is that a command? I don't know much of what the code is doing in the tutorial just what is required – Sqeak Apr 14 at 18:06
  • I mean what is cap.read(). Please add a print(cap.read()) to your loop and tell us. – Jakob Apr 14 at 18:09
  • Added it to question – Sqeak Apr 14 at 18:21
  • Try running with the other Python version. If using Python2 try Python3 and vice versa. – joan Apr 15 at 8:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.