MrinalJain17 / Human-Activity-Recognition

Recognizing human activities using Deep Learning
MIT License
48 stars 31 forks source link

Memory Error #6

Closed bit-scientist closed 6 years ago

bit-scientist commented 6 years ago

I encountered an error when I tried reading

X_test = reader.read_videos(test_files)
y_test = to_categorical(test_targets, num_classes=6)
print('Shape of testing data:', X_test.shape)
print('Shape of testing labels:', y_test.shape)

It went on untill 100%, showing in the indicator 100%|██████████| 200/200 [02:41<00:00, 1.12s/it] Then I received

Traceback (most recent call last):

  File "<ipython-input-6-5d58c65a1c01>", line 1, in <module>
    X_test = reader.read_videos(test_files)

  File "D:\Projects\HAR\Human-Activity-Recognition\utils.py", line 73, in read_videos
    tensor = np.vstack(list_of_videos)

  File "C:\Users\usrname\Anaconda3\envs\py35\lib\site-packages\numpy\core\shape_base.py", line 234, in vstack
    return _nx.concatenate([atleast_2d(_m) for _m in tup], 0)

MemoryError

I am using GTX 1080 on Window 10, spyder (through anaconda env). What do you think the problem might be?

MrinalJain17 commented 6 years ago

You get a memory error when the system does not have enough memory (RAM) to load the entire data. Now, in this scenario, you could do one of the following:

  1. Read the data/videos in batches.
  2. Resize the frames of the video - this saves a lot of memory. Set target_size to something like (360, 240).
  3. Frame skipping: Select only specific frames, instead of the entire video. Use num_frames to achieve this.
  4. Converting the video to grayscale.
  5. Use 2, 3 and 4 in combination.
  6. Or, as a last resort, get more RAM. Or, run the model on the cloud (like on AWS EC2 instances).
bit-scientist commented 6 years ago

@MrinalJain17 Thank you, my RAM is 32Gb, isn't it enough? When I tried after some time it worked like a charm

MrinalJain17 commented 6 years ago

While executing the project, I did not keep track of the memory usage since I was using an AWS EC2 instance having 61 GB RAM. So, I cannot exactly say whether 32 GB is enough or not, but there is a possibility that it might not be. Did you make any modifications to the read_videos() or did it worked as it is? @bit-scientist

Malathi15 commented 5 years ago

@MrinalJain17 I also have the same Memory Error. So I tried to use pre-trained model. When I read My own video using helper class Video in utils.py. I have this Error

ValueError: No way to determine width or height from video. Need -s in inputdict. Consult documentation on I/O

This the code I run

import numpy as np
    from utils import Videos

    reader = Videos(target_size=(128, 128), 
            to_gray=True, 
                    max_frames=40, 
                    extract_frames='first', 
                    required_fps=5, 
                    normalize_pixels=(-1, 1))

    videos = reader.read_videos('./data/sample.avi')
MrinalJain17 commented 5 years ago

@Malathi15 Usually, one would get such an error if the video does not contain the appropriate metadata (it might be possible that the video is corrupt). I suggest you try opening the video in some video player (like VLC) and see if it works.

If it does, then there might be a bug in the helper class. However, the utility in this repo is no longer in active development. Therefore, I suggest you use the following library - mydia - for reading the videos. It is an enhanced version of the utility provided in this repo, and has the (almost) same API.

Malathi15 commented 5 years ago

@MrinalJain17 when I tried it using mydia I got another error.. I have run code using mydia

from mydia import Videos
video_path = r".docs/examples/sample_video/bigbuckbunny.mp4"
reader = Videos()
video = reader.read(video_path)

I got this error

  0%|          | 0/1 [00:00<?, ?videos/s]ffprobe version 3.4.4-0ubuntu0.18.04.1 Copyright (c) 2007-2018 the FFmpeg developers
  built with gcc 7 (Ubuntu 7.3.0-16ubuntu3)
  configuration: --prefix=/usr --extra-version=0ubuntu0.18.04.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-librsvg --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared
  libavutil      55. 78.100 / 55. 78.100
  libavcodec     57.107.100 / 57.107.100
  libavformat    57. 83.100 / 57. 83.100
  libavdevice    57. 10.100 / 57. 10.100
  libavfilter     6.107.100 /  6.107.100
  libavresample   3.  7.  0 /  3.  7.  0
  libswscale      4.  8.100 /  4.  8.100
  libswresample   2.  9.100 /  2.  9.100
  libpostproc    54.  7.100 / 54.  7.100
.docs/examples/sample_video/bigbuckbunny.mp4: No such file or directory

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-21-9453e4bb0e2d> in <module>()
----> 1 video = reader.read(video_path)

/usr/local/lib/python3.6/dist-packages/mydia/mydia.py in read(self, paths, verbose, workers)
    232         else:
    233             paths_iterator = tqdm(paths, unit="videos", disable=disable)
--> 234             video_tensor = np.vstack(map(self._read_video, paths_iterator))
    235 
    236         if self.data_format == "channels_first":

/usr/local/lib/python3.6/dist-packages/numpy/core/shape_base.py in vstack(tup)
    232 
    233     """
--> 234     return _nx.concatenate([atleast_2d(_m) for _m in tup], 0)
    235 
    236 def hstack(tup):

/usr/local/lib/python3.6/dist-packages/numpy/core/shape_base.py in <listcomp>(.0)
    232 
    233     """
--> 234     return _nx.concatenate([atleast_2d(_m) for _m in tup], 0)
    235 
    236 def hstack(tup):

/usr/local/lib/python3.6/dist-packages/mydia/mydia.py in _read_video(self, path)
    284 
    285         """
--> 286         fps, total_frames = self._probe(path)
    287         width = self.target_size.width
    288         height = self.target_size.height

TypeError: 'NoneType' object is not iterable
MrinalJain17 commented 5 years ago
0%|          | 0/1 [00:00<?, ?videos/s]ffprobe version 3.4.4-0ubuntu0.18.04.1 Copyright (c) 2007-2018 the FFmpeg developers
built with gcc 7 (Ubuntu 7.3.0-16ubuntu3)
configuration: --prefix=/usr --extra-version=0ubuntu0.18.04.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-librsvg --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared
libavutil      55. 78.100 / 55. 78.100
libavcodec     57.107.100 / 57.107.100
libavformat    57. 83.100 / 57. 83.100
libavdevice    57. 10.100 / 57. 10.100
libavfilter     6.107.100 /  6.107.100
libavresample   3.  7.  0 /  3.  7.  0
libswscale      4.  8.100 /  4.  8.100
libswresample   2.  9.100 /  2.  9.100
libpostproc    54.  7.100 / 54.  7.100
.docs/examples/sample_video/bigbuckbunny.mp4: No such file or directory

The last line clearly indicates that the video is not present at the specified path.

In the example provided in the docs, you need to set video_path to point to the video on your local machine.

Malathi15 commented 5 years ago

@MrinalJain17 Thanks for your reply. Actually I run the comment in mydia model directory so I give the video_path as video_path = r".docs/examples/sample_video/bigbuckbunny.mp4" I have the video file in this directory still I got the error No such file or directory that's why I ask this question. After getting your ans I give the full video path video_path = r"C:\Users\mala\Desktop\mydia-master\docs\examples\sample_video\bigbuckbunny.mp4" Now it work..

MohitMourya commented 5 years ago

You get a memory error when the system does not have enough memory (RAM) to load the entire data. Now, in this scenario, you could do one of the following:

1. Read the data/videos in batches.

2. Resize the frames of the video - this saves a lot of memory. Set `target_size` to something like `(360, 240)`.

3. Frame skipping: Select only specific frames, instead of the entire video. Use `num_frames` to achieve this.

4. Converting the video to grayscale.

5. Use _2_, _3_ and _4_ in combination.

6. Or, as a last resort, get more RAM. Or, run the model on the cloud (like on AWS EC2 instances).

I tried option 2 and 4 still same error. Couldn't figure out where to specify num_frames parameter. can you please provide code to read the videos in batches?