Skip to content
GitLab
Explorer
Connexion
S'inscrire
Navigation principale
Rechercher ou aller à…
Projet
M
ModelCIMs_framework
Gestion
Activité
Membres
Labels
Programmation
Wiki
Code
Requêtes de fusion
Dépôt
Branches
Validations
Étiquettes
Graphe du dépôt
Comparer les révisions
Compilation
Pipelines
Jobs
Planifications de pipeline
Artéfacts
Déploiement
Releases
Registre de paquets
Registre de conteneur
Registre de modèles
Opération
Modules Terraform
Analyse
Données d'analyse des chaînes de valeur
Analyse des contributeurs
Données d'analyse CI/CD
Données d'analyse du dépôt
Expériences du modèle
Aide
Aide
Support
Documentation de GitLab
Comparer les forfaits GitLab
Forum de la communauté
Contribuer à GitLab
Donner votre avis
Conditions générales et politique de confidentialité
Raccourcis clavier
?
Extraits de code
Groupes
Projets
Afficher davantage de fils d'Ariane
Adrian Kneip
ModelCIMs_framework
Validations
a0fa316d
Valider
a0fa316d
rédigé
2 years ago
par
Adrian Kneip
Parcourir les fichiers
Options
Téléchargements
Correctifs
Plain Diff
Upload New File
parent
2ef3acd5
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Modifications
1
Masquer les modifications d'espaces
En ligne
Côte à côte
Affichage de
1 fichier modifié
utils/load_data.py
+105
-0
105 ajouts, 0 suppression
utils/load_data.py
avec
105 ajouts
et
0 suppression
utils/load_data.py
0 → 100644
+
105
−
0
Voir le fichier @
a0fa316d
# Copyright 2017 Bert Moons
# This file is part of QNN.
# QNN is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# QNN 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 General Public License for more details.
# The code for QNN is based on BinaryNet: https://github.com/MatthieuCourbariaux/BinaryNet
# You should have received a copy of the GNU General Public License
# along with QNN. If not, see <http://www.gnu.org/licenses/>.
import
numpy
as
np
from
my_datasets
import
my_cifar10
from
my_datasets
import
my_mnist
def
load_dataset
(
dataset
):
if
(
dataset
==
"
CIFAR-10
"
):
print
(
'
Loading CIFAR-10 dataset...
'
)
#train_set_size = 45000
#train_set = cifar10(which_set="train", start=0, stop=train_set_size)
#valid_set = cifar10(which_set="train", start=train_set_size, stop=50000)
#test_set = cifar10(which_set="test")
(
train_set_X
,
train_set_Y
),(
valid_set_X
,
valid_set_Y
)
=
my_cifar10
.
load_data
()
train_set_X
=
np
.
transpose
(
np
.
reshape
(
np
.
subtract
(
np
.
multiply
(
2.
/
255.
,
train_set_X
),
1.
),
(
-
1
,
3
,
32
,
32
)),(
0
,
2
,
3
,
1
))
valid_set_X
=
np
.
transpose
(
np
.
reshape
(
np
.
subtract
(
np
.
multiply
(
2.
/
255.
,
valid_set_X
),
1.
),
(
-
1
,
3
,
32
,
32
)),(
0
,
2
,
3
,
1
))
#test_set.X = np.transpose(np.reshape(np.subtract(np.multiply(2. / 255., test_set.X), 1.), (-1, 3, 32, 32)),(0,2,3,1))
# flatten targets
train_set_Y
=
np
.
hstack
(
train_set_Y
)
valid_set_Y
=
np
.
hstack
(
valid_set_Y
)
#test_set.y = np.hstack(test_set.y)
# Onehot the targets
train_set_Y
=
np
.
float32
(
np
.
eye
(
10
)[
train_set_Y
])
valid_set_Y
=
np
.
float32
(
np
.
eye
(
10
)[
valid_set_Y
])
#test_set.y = np.float32(np.eye(10)[test_set.y])
# for hinge loss
train_set_Y
=
2
*
train_set_Y
-
1.
valid_set_Y
=
2
*
valid_set_Y
-
1.
#test_set.y = 2 * test_set.y - 1.
# enlarge train data set by mirrroring
x_train_flip
=
train_set_X
[:,
:,
::
-
1
,
:]
y_train_flip
=
train_set_Y
train_set_X
=
np
.
concatenate
((
train_set_X
,
x_train_flip
),
axis
=
0
)
train_set_Y
=
np
.
concatenate
((
train_set_Y
,
y_train_flip
),
axis
=
0
)
elif
(
dataset
==
"
MNIST
"
):
print
(
'
Loading MNIST dataset...
'
)
#train_set_size = 50000
#train_set = mnist(which_set="train", start=0, stop=train_set_size)
#valid_set = mnist(which_set="train", start=train_set_size, stop=60000)
#test_set = mnist(which_set="test")
path_to_file
=
'
../my_datasets/mnist.npz
'
(
train_set_X
,
train_set_Y
),(
valid_set_X
,
valid_set_Y
)
=
my_mnist
.
load_data
(
path_to_file
)
train_set_X
=
np
.
transpose
(
np
.
reshape
(
np
.
subtract
(
np
.
multiply
(
2.
/
255.
,
train_set_X
),
1.
),
(
-
1
,
1
,
28
,
28
)),(
0
,
2
,
3
,
1
))
valid_set_X
=
np
.
transpose
(
np
.
reshape
(
np
.
subtract
(
np
.
multiply
(
2.
/
255.
,
valid_set_X
),
1.
),
(
-
1
,
1
,
28
,
28
)),(
0
,
2
,
3
,
1
))
#test_set.X = np.transpose(np.reshape(np.subtract(np.multiply(2. / 255., test_set.X), 1.), (-1, 1, 28, 28)),(0,2,3,1))
# flatten targets
train_set_Y
=
np
.
hstack
(
train_set_Y
)
valid_set_Y
=
np
.
hstack
(
valid_set_Y
)
#test_set.y = np.hstack(test_set.y)
# Onehot the targets
train_set_Y
=
np
.
float32
(
np
.
eye
(
10
)[
train_set_Y
])
valid_set_Y
=
np
.
float32
(
np
.
eye
(
10
)[
valid_set_Y
])
#test_set.y = np.float32(np.eye(10)[test_set.y])
# for hinge loss
train_set_Y
=
2
*
train_set_Y
-
1.
valid_set_Y
=
2
*
valid_set_Y
-
1.
#test_set.y = 2 * test_set.y - 1.
# enlarge train data set by mirrroring
x_train_flip
=
train_set_X
[:,
:,
::
-
1
,
:]
y_train_flip
=
train_set_Y
train_set_X
=
np
.
concatenate
((
train_set_X
,
x_train_flip
),
axis
=
0
)
train_set_Y
=
np
.
concatenate
((
train_set_Y
,
y_train_flip
),
axis
=
0
)
else
:
print
(
"
wrong dataset given
"
)
train_set
=
(
train_set_X
,
train_set_Y
)
valid_set
=
(
valid_set_X
,
valid_set_Y
)
return
train_set
,
valid_set
Ce diff est replié.
Cliquez pour l'agrandir.
Aperçu
0%
Chargement en cours
Veuillez réessayer
ou
joindre un nouveau fichier
.
Annuler
You are about to add
0
people
to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Enregistrer le commentaire
Annuler
Veuillez vous
inscrire
ou vous
se connecter
pour commenter