Commit 9a2a2188 authored by nstorni's avatar nstorni
Browse files

Buf fix of video2frames, typos in readme.

parent 598ccf14
......@@ -16,35 +16,50 @@ $HOME/world-models/install_requirements.sh
## 2. Mini Mice dataset preparation
Prepare folder structure in $SCRATCH directory:
```bash
DATASET_NAME="mini_mice_dataset"
mkdir $SCRATCH/data
mkdir $SCRATCH/data/mini_mice_dataset
mkdir $SCRATCH/data/mini_mice_dataset/video
mkdir $SCRATCH/data/mini_mice_dataset/train
mkdir $SCRATCH/data/mini_mice_dataset/train/nolabel
mkdir $SCRATCH/data/mini_mice_dataset/val
mkdir $SCRATCH/data/mini_mice_dataset/val/nolabel
mkdir $SCRATCH/data/mini_mice_dataset/test
mkdir $SCRATCH/data/mini_mice_dataset/test/nolabel
mkdir $SCRATCH/data/$DATASET_NAME
mkdir $SCRATCH/data/$DATASET_NAME/video
mkdir $SCRATCH/data/$DATASET_NAME/train
mkdir $SCRATCH/data/$DATASET_NAME/train/nolabel
mkdir $SCRATCH/data/$DATASET_NAME/val
mkdir $SCRATCH/data/$DATASET_NAME/val/nolabel
mkdir $SCRATCH/data/$DATASET_NAME/test
mkdir $SCRATCH/data/$DATASET_NAME/test/nolabel
```
This structure is required for the dataset loader to load each picture (it expects a folder containing subfolders for each class, in our case we have only one class "nolabel").
Load one video to $SCRATCH/data/mini_mice_dataset/video using winSCP or similar.
Load one video to $SCRATCH/data/$DATASET_NAME/video using winSCP or similar.
E.g copy from local (ON YOUR LOCAL MACHINE) directory video.avi to the target directory in the cloud.:
```bash
scp OFT_1.mp4 USERNAME@login.leonhard.ethz.ch:$SCRATCH/data/mini_mice_dataset/video
scp *.mp4 nstorni@login.leonhard.ethz.ch:$SCRATCH/data/mini_mice_dataset/video
```
Extract frames from videos:
Extract frames from videos (takes a long time, for many videos submit as a job to the cluster, command next):
```bash
cd $SCRATCH/data/$DATASET_NAME
$HOME/world-models/video_frame/video2frames.sh
cd $HOME
```
Move some images from train to test folder (not really random, just taking all the file ending with 1 in the filename).
As it is quite slow at extracting the frames, if you want ot extract multiple video and don't won't to leave the ssh connection open you can submit a job to the cluster that will extract the frames:
```bash
bsub -n 1 -R "rusage[mem=4096]" "cd $SCRATCH/data/mini_mice_dataset; pwd; $HOME/world-models/video_frame/video2frames.sh"
```
You can check the job status by tiping:
```bash
bbjobs
```
Move some images from train to test folder (not really random, just taking all the file ending with 1 in the filename) should be about 10% of the train set.
```bash
cd $SCRATCH/data/mini_mice_dataset
cp train/nolabel/*1.png val/nolabel
cd $SCRATCH/data/$DATASET_NAME
mv train/nolabel/*1.png val/nolabel
```
......
import cv2
import glob
import os
input_dir = os.path.expandvars("$SCRATCH/data/mini_mice_dataset/video")
output_dir = os.path.expandvars("$SCRATCH/data/mini_mice_dataset/train/nolabel")
input_dir = os.path.expandvars("video")
output_dir = os.path.expandvars("train/nolabel")
vid_num = 1
for v in glob.iglob(input_dir + "/*.mp4"):
vidcap = cv2.VideoCapture(v)
print("Processing" + v)
success, image = vidcap.read()
vid_num = 1
count = 0
print("This video is labeled as No." + str(vid_num))
while success:
#image = image[50:500, 170:750] # crop
print(count)
# print(count)
cv2.imwrite(output_dir + "/" + str(vid_num) + "_frame_" + str(count) + ".png", image) # save frame as JPEG file
success,image = vidcap.read()
count += 1
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment