thoughtworksarts / EmoPy

A deep neural net toolkit for emotion analysis via Facial Expression Recognition (FER)
https://thoughtworksarts.io/blog/emopy-emotional-expression-toolkit/
GNU Affero General Public License v3.0
919 stars 264 forks source link

error new images apply to examples #55

Open Antwnina opened 4 years ago

Antwnina commented 4 years ago

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'
cptanalatriste commented 4 years ago

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.

Antwnina commented 4 years ago

@cptanalatriste

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()