error new images apply to examples · Issue #55 · thoughtworksarts/EmoPy · GitHub
Skip to content

error new images apply to examples #55

Open

Description

@Antwnina

Hello, i want to capture some pictures of mine and load them to fermodel_example.py.
How do I do that? I've changed the size frame and made the .png gray but it is not accepted

import cv2
import numpy as np
import os
import imutils

cap = cv2.VideoCapture(0)
path = '/home/pi/EmoPy/EmoPy/examples/image_data'
while(cap.isOpened()):
    ret, frame = cap.read()

    frame = imutils.resize(frame, width=640, height=360)
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

    cv2.imshow('frame', gray)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        cv2.imwrite(os.path.join(path , 'wakaGr.png'), gray)
        break

cap.release()
cv2.destroyAllWindows()

and this is the terminal output when i run the example (i made duplicate)

pi@raspberrypi:~/EmoPy/EmoPy/examples $ python3.6 fermodel_ex_take.py 
Using TensorFlow backend.
/usr/local/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:516: 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_qint8 = np.dtype([("qint8", np.int8, 1)])
/usr/local/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:517: 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)])
/usr/local/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:518: 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)])
/usr/local/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:519: 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)])
/usr/local/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:520: 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)])
/usr/local/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:525: 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)])
/usr/local/lib/python3.6/importlib/_bootstrap.py:219: RuntimeWarning: compiletime version 3.4 of module 'tensorflow.python.framework.fast_tensor_util' does not match runtime version 3.6
  return f(*args, **kwds)
/usr/local/lib/python3.6/importlib/_bootstrap.py:219: RuntimeWarning: builtins.type size changed, may indicate binary incompatibility. Expected 432, got 412
  return f(*args, **kwds)
/usr/local/lib/python3.6/site-packages/tensorboard/compat/tensorflow_stub/dtypes.py:541: 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_qint8 = np.dtype([("qint8", np.int8, 1)])
/usr/local/lib/python3.6/site-packages/tensorboard/compat/tensorflow_stub/dtypes.py:542: 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)])
/usr/local/lib/python3.6/site-packages/tensorboard/compat/tensorflow_stub/dtypes.py:543: 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)])
/usr/local/lib/python3.6/site-packages/tensorboard/compat/tensorflow_stub/dtypes.py:544: 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)])
/usr/local/lib/python3.6/site-packages/tensorboard/compat/tensorflow_stub/dtypes.py:545: 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)])
/usr/local/lib/python3.6/site-packages/tensorboard/compat/tensorflow_stub/dtypes.py:550: 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)])
Initializing FER model parameters for target emotions: ['calm', 'anger', 'happiness']
WARNING:tensorflow:From /usr/local/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py:74: The name tf.get_default_graph is deprecated. Please use tf.compat.v1.get_default_graph instead.

WARNING:tensorflow:From /usr/local/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py:517: The name tf.placeholder is deprecated. Please use tf.compat.v1.placeholder instead.

WARNING:tensorflow:From /usr/local/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py:4138: The name tf.random_uniform is deprecated. Please use tf.random.uniform instead.

WARNING:tensorflow:From /usr/local/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py:174: The name tf.get_default_session is deprecated. Please use tf.compat.v1.get_default_session instead.

WARNING:tensorflow:From /usr/local/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py:181: The name tf.ConfigProto is deprecated. Please use tf.compat.v1.ConfigProto instead.

WARNING:tensorflow:From /usr/local/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py:3976: The name tf.nn.max_pool is deprecated. Please use tf.nn.max_pool2d instead.

WARNING:tensorflow:From /usr/local/lib/python3.6/site-packages/keras/optimizers.py:790: The name tf.train.Optimizer is deprecated. Please use tf.compat.v1.train.Optimizer instead.

WARNING:tensorflow:From /usr/local/lib/python3.6/site-packages/tensorflow/python/ops/math_grad.py:1250: add_dispatch_support.<locals>.wrapper (from tensorflow.python.ops.array_ops) is deprecated and will be removed in a future version.
Instructions for updating:
Use tf.where in 2.0, which has the same broadcast rule as np.where
Predicting on happy image...
Traceback (most recent call last):
  File "fermodel_ex_take.py", line 28, in <module>
    model.predict(resource_filename('EmoPy.examples','image_data/wakaGr.png'))
  File "/usr/local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 1143, in resource_filename
    self, resource_name
  File "/usr/local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 1650, in get_resource_filename
    return self._extract_resource(manager, zip_path)
  File "/usr/local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 1671, in _extract_resource
    timestamp, size = self._get_date_and_size(self.zipinfo[zip_path])
KeyError: 'EmoPy/examples/image_data/wakaGr.png'

Activity

  1. changed the title [-]new images apply to examples[/-] [+]error new images apply to examples[/+] on Dec 15, 2019
  2. cptanalatriste commented on Dec 15, 2019

    @cptanalatriste
    Contributor

    Are you trying to take pictures using the webcam? If that's the case, you can use this example as a reference: https://github.com/thoughtworksarts/EmoPy/blob/master/EmoPy/examples/fermodel_example_webcam.py

    Before doing that, please make sure you have downloaded the last version of EmoPy and installed it properly, as described in our README file. You can verify that by running the tests first.

  3. Antwnina commented on Dec 15, 2019

    @Antwnina
    Author

    @cptanalatriste

    • i'm using raspberry pi 4B i run the whole example without venv, and i prefere pip than homebrew
    • also another point is that i already did that but i cannot see the window of capturing the image...
    • i run that example but the angry emotion is very intense i mean the result shows everytime the angry with the bigger %
    • also i tried to add all of the rest emotions and there is error
    def get_emotion_from_camera():
    
        # Specify the camera which you want to use. The default argument is '0'
        video_capture = cv2.VideoCapture(0)
        file = 'image_data/image.jpg'
        frame = capture_image(video_capture, file)
    
        if frame is not None:
            # Can choose other target emotions from the emotion subset defined in
                    # fermodel.py in src directory. The function
            # defined as `def _check_emotion_set_is_supported(self):`
            target_emotions = ['calm', 'anger', 'happiness', 'surprise', 'disgust', 'fear', 'sadness'] #'calm', 'anger', 'happiness']
            model = FERModel(target_emotions, verbose=True)
    
            frame_string = model.predict(file)
            display_prediction(frame, frame_string)
    

    error in terminal

    python3.6 fermodel_ex_webcam_motor.py
    Using TensorFlow backend.
    /usr/local/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:516: 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_qint8 = np.dtype([("qint8", np.int8, 1)])
    /usr/local/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:517: 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)])
    /usr/local/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:518: 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)])
    /usr/local/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:519: 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)])
    /usr/local/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:520: 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)])
    /usr/local/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:525: 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)])
    /usr/local/lib/python3.6/importlib/_bootstrap.py:219: RuntimeWarning: compiletime version 3.4 of module 'tensorflow.python.framework.fast_tensor_util' does not match runtime version 3.6
      return f(*args, **kwds)
    /usr/local/lib/python3.6/importlib/_bootstrap.py:219: RuntimeWarning: builtins.type size changed, may indicate binary incompatibility. Expected 432, got 412
      return f(*args, **kwds)
    /usr/local/lib/python3.6/site-packages/tensorboard/compat/tensorflow_stub/dtypes.py:541: 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_qint8 = np.dtype([("qint8", np.int8, 1)])
    /usr/local/lib/python3.6/site-packages/tensorboard/compat/tensorflow_stub/dtypes.py:542: 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)])
    /usr/local/lib/python3.6/site-packages/tensorboard/compat/tensorflow_stub/dtypes.py:543: 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)])
    /usr/local/lib/python3.6/site-packages/tensorboard/compat/tensorflow_stub/dtypes.py:544: 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)])
    /usr/local/lib/python3.6/site-packages/tensorboard/compat/tensorflow_stub/dtypes.py:545: 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)])
    /usr/local/lib/python3.6/site-packages/tensorboard/compat/tensorflow_stub/dtypes.py:550: 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)])
    Capturing image ...
    Image written to:  image_data/image.jpg
    Initializing FER model parameters for target emotions: ['calm', 'anger', 'happiness', 'surprise', 'disgust', 'fear', 'sadness']
    Traceback (most recent call last):
      File "fermodel_ex_webcam_motor.py", line 106, in <module>
        get_emotion_from_camera()
      File "fermodel_ex_webcam_motor.py", line 76, in get_emotion_from_camera
        model = FERModel(target_emotions, verbose=True)
      File "/usr/local/lib/python3.6/site-packages/EmoPy-0.0.5-py3.6.egg/EmoPy/src/fermodel.py", line 41, in __init__
      File "/usr/local/lib/python3.6/site-packages/EmoPy-0.0.5-py3.6.egg/EmoPy/src/fermodel.py", line 45, in _initialize_model
      File "/usr/local/lib/python3.6/site-packages/EmoPy-0.0.5-py3.6.egg/EmoPy/src/fermodel.py", line 112, in _choose_model_from_target_emotions
      File "/usr/local/lib/python3.6/site-packages/keras/engine/saving.py", line 417, in load_model
        f = h5dict(filepath, 'r')
      File "/usr/local/lib/python3.6/site-packages/keras/utils/io_utils.py", line 186, in __init__
        self.data = h5py.File(path, mode=mode)
      File "/usr/local/lib/python3.6/site-packages/h5py/_hl/files.py", line 408, in __init__
        swmr=swmr)
      File "/usr/local/lib/python3.6/site-packages/h5py/_hl/files.py", line 173, in make_fid
        fid = h5f.open(name, flags, fapl=fapl)
      File "h5py/_objects.pyx", line 54, in h5py._objects.with_phil.wrapper
      File "h5py/_objects.pyx", line 55, in h5py._objects.with_phil.wrapper
      File "h5py/h5f.pyx", line 88, in h5py.h5f.open
    OSError: Unable to open file (file signature not found)
    
    

    but i have h5py because i checked it you cna see below

    pi@raspberrypi:~/EmoPy/EmoPy/examples $ sudo apt-get install python3-h5py
    Reading package lists... Done
    Building dependency tree       
    Reading state information... Done
    python3-h5py is already the newest version (2.8.0-3).
    0 upgraded, 0 newly installed, 0 to remove and 117 not upgraded.
    pi@raspberrypi:~/EmoPy/EmoPy/examples $ sudo pip3 install h5py
    Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
    Requirement already satisfied: h5py in /usr/local/lib/python3.6/site-packages (2.10.0)
    Requirement already satisfied: numpy>=1.7 in /usr/local/lib/python3.6/site-packages (from h5py) (1.17.4)
    Requirement already satisfied: six in /usr/local/lib/python3.6/site-packages (from h5py) (1.13.0)
    pi@raspberrypi:~/EmoPy/EmoPy/examples $ ipython
    Python 3.6.9 (default, Nov 11 2019, 21:26:11) 
    Type 'copyright', 'credits' or 'license' for more information
    IPython 7.9.0 -- An enhanced Interactive Python. Type '?' for help.
    
    In [1]: import h5py                                                             
    
    In [2]: h5py.run_tests()                                                        
    ============================= test session starts ==============================
    platform linux -- Python 3.6.9, pytest-5.2.2, py-1.8.0, pluggy-0.13.0
    rootdir: /home/pi/EmoPy
    collected 549 items                                                            
    
    ../../tests/test_attribute_create.py ....                                [  0%]
    ../../tests/test_attrs.py ................s                              [  3%]
    ../../tests/test_attrs_data.py ....................                      [  7%]
    ../../tests/test_base.py .....                                           [  8%]
    ../../tests/test_completions.py ..                                       [  8%]
    ../../tests/test_dataset.py .s.......x.................................. [ 16%]
    ...............................x..........................               [ 27%]
    ../../tests/test_dataset_getitem.py .................................... [ 33%]
    .............x...................................s                       [ 42%]
    ../../tests/test_dataset_swmr.py ssss..........                          [ 45%]
    ../../tests/test_datatype.py ..                                          [ 45%]
    ../../tests/test_deprecation.py .                                        [ 46%]
    ../../tests/test_dimension_scales.py ....s................               [ 49%]
    ../../tests/test_dims_dimensionproxy.py .                                [ 50%]
    ../../tests/test_dtype.py ................ssss                           [ 53%]
    ../../tests/test_file.py .............ss...ssss....................s.... [ 62%]
    .....                                                                    [ 63%]
    ../../tests/test_file2.py .................                              [ 66%]
    ../../tests/test_file_image.py ..                                        [ 66%]
    ../../tests/test_filters.py ...                                          [ 67%]
    ../../tests/test_group.py .................................ssssss....... [ 75%]
    ............................................                             [ 83%]
    ../../tests/test_h5.py .....                                             [ 84%]
    ../../tests/test_h5d_direct_chunk.py ....                                [ 85%]
    ../../tests/test_h5f.py .....                                            [ 86%]
    ../../tests/test_h5p.py ........                                         [ 87%]
    ../../tests/test_h5pl.py ......                                                                  [ 88%]
    ../../tests/test_h5t.py ....                                                                     [ 89%]
    ../../tests/test_objects.py ...                                                                  [ 89%]
    ../../tests/test_selections.py ....                                                              [ 90%]
    ../../tests/test_slicing.py ........................                                             [ 95%]
    ../../tests/test_threads.py ..                                                                   [ 95%]
    ../../tests/test_vds/test_highlevel_vds.py ......                                                [ 96%]
    ../../tests/test_vds/test_lowlevel_vds.py ...                                                    [ 97%]
    ../../tests/test_vds/test_virtual_source.py ................                                     [100%]
    
    =========================================== warnings summary ===========================================
    tests/test_dataset_getitem.py::Test1DZeroFloat::test_mask
      /usr/local/lib/python3.6/site-packages/h5py/_hl/dataset.py:533: DeprecationWarning: The truth value of an empty array is ambiguous. Returning False, but in future this will result in an error. Use `array.size > 0` to check that an array is not empty.
        if args == (Ellipsis,) or args == tuple():
    
    -- Docs: https://docs.pytest.org/en/latest/warnings.html
    ======================= 521 passed, 25 skipped, 3 xfailed, 1 warnings in 21.61s ========================
    Out[2]: 0
    
    In [3]: quit()  
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions