57 lines (52 with data), 5.4 kB
B
Co^4 ã @ s d Z ddlmZ ddlT ddlZddlmZ ddlm Z ddl
mZ ddlZ
dd ZG dd deZdd
dZdddZdd ZdS )a
Created by Victor Delvigne
ISIA Lab, Faculty of Engineering University of Mons, Mons (Belgium)
victor.delvigne@umons.ac.be
Source: Bashivan, et al."Learning Representations from EEG with Deep Recurrent-Convolutional Neural Networks." International conference on learning representations (2016).
Copyright (C) 2019 - UMons
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
é )ÚDataset)Ú*Nc C s t | ¡}t j |¡ t| | }g }g }x^t|D ]R}| ||| |d |
¡ | t |d||
||d | d
g¡¡ q4W ||fS )Né r éÿÿÿÿ)ÚnpÚarangeÚrandomÚshuffleÚintÚrangeÚappendÚhstack)ÚlengthZn_foldZtot_idZlen_foldZtrain_idZtest_idÚi© r ú5/home/vdelv/PycharmProjects/EEGLearn_Pytorch/Utils.pyÚkfold# s
4r c @ s( e Zd ZdZdd Zdd Zdd ZdS ) ÚEEGImagesDatasetz!EEGLearn Images Dataset from EEG.c C s || _ || _d S )N)ÚlabelÚImages)Úselfr Úimager r r Ú__init__2 s zEEGImagesDataset.__init__c C s
t | jS )N)Úlenr )r r r r Ú__len__6 s zEEGImagesDataset.__len__c C s2 t |¡r| ¡ }| j| }| j| }||f}|S )N)ÚtorchÚ is_tensorÚtolistr r )r Úidxr r Úsampler r r Ú__getitem__9 s
zEEGImagesDataset.__getitem__N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r r r r r r r r / s r Tc C s¼ d}g }xt |dD ]r\}}|\}} | tj¡}|r<| ¡ }| |}
t |
¡ jd¡\}}| || k ¡ ¡ ||
| ¡ }
||
¡ 7 }qW ||d }dd |D }t|t| }||fS )Ng r r c S s g | ]}|D ]}|qqS r r )Ú.0ÚsublistÚitemr r r ú
<listcomp>R s zTest_Model.<locals>.<listcomp>)
Ú enumerateÚtor Úfloat32ÚcudaÚmaxÚcpuÚdatar r r'