Ce serveur Gitlab sera éteint le 30 juin 2020, pensez à migrer vos projets vers les serveurs gitlab-research.centralesupelec.fr et gitlab-student.centralesupelec.fr !

Commit b87a7a31 authored by Hachemin Pierre-Yves's avatar Hachemin Pierre-Yves

Keras first shot

parent 8f848843
{
"cells": [
{
"cell_type": "code",
"execution_count": 30,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(None, None, 1)\n",
"(None, None, 1)\n",
"(None, None, 1)\n",
"(None, None, 19)\n"
]
}
],
"source": [
"from keras.models import Sequential\n",
"from keras.layers import Dense, Activation\n",
"from keras.layers import Conv1D, MaxPooling1D\n",
"from keras.layers import Conv2D, MaxPooling2D, Conv2DTranspose, Concatenate\n",
"from keras.layers import Reshape, Flatten, UpSampling2D\n",
"from keras.layers import Dropout, Average, BatchNormalization\n",
"from keras.layers import Dense, Dropout, Flatten, Input, Cropping2D, ZeroPadding2D\n",
"\n",
"num_classes=19\n",
"\n",
"#Hyperparameters\n",
"filtersCNN1=1\n",
"kernelSize1=3\n",
"\n",
"filtersCNN2=1\n",
"kernelSize2=3\n",
"\n",
"unitsFC1=1000\n",
"unitsFC2=num_classes\n",
"\n",
"#defining the layers architecture\n",
"\n",
"model = Sequential()\n",
"model.add(Conv1D(filtersCNN1,kernelSize1,strides=1, padding=\"valid\", activation='relu',input_shape=(None,3)))\n",
"print(model.output_shape)\n",
"model.add(MaxPooling1D(pool_size=2,strides=None,padding=\"valid\"))\n",
"#BatchNormalization(axis=3)\n",
"model.add(Dropout(0.5))\n",
"print(model.output_shape)\n",
"\n",
"model.add(Conv1D(filtersCNN2,kernelSize2,strides=1, padding=\"valid\", activation='relu',input_shape=(None,3)))\n",
"model.add(MaxPooling1D(pool_size=2,strides=None,padding=\"valid\"))\n",
"#BatchNormalization(axis=3)\n",
"print(model.output_shape)\n",
"\n",
"model.add(Dense(1000, activation='relu'))\n",
"model.add(Dense(num_classes, activation='softmax'))\n",
"print(model.output_shape)"
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"_________________________________________________________________\n",
"Layer (type) Output Shape Param # \n",
"=================================================================\n",
"conv1d_24 (Conv1D) (None, None, 1) 10 \n",
"_________________________________________________________________\n",
"max_pooling1d_16 (MaxPooling (None, None, 1) 0 \n",
"_________________________________________________________________\n",
"dropout_10 (Dropout) (None, None, 1) 0 \n",
"_________________________________________________________________\n",
"conv1d_25 (Conv1D) (None, None, 1) 4 \n",
"_________________________________________________________________\n",
"max_pooling1d_17 (MaxPooling (None, None, 1) 0 \n",
"_________________________________________________________________\n",
"dense_6 (Dense) (None, None, 1000) 2000 \n",
"_________________________________________________________________\n",
"dense_7 (Dense) (None, None, 19) 19019 \n",
"=================================================================\n",
"Total params: 21,033\n",
"Trainable params: 21,033\n",
"Non-trainable params: 0\n",
"_________________________________________________________________\n"
]
}
],
"source": [
"model.summary()"
]
},
{
"cell_type": "code",
"execution_count": 28,
"metadata": {},
"outputs": [],
"source": [
"model.compile(loss='categorical_crossentropy',\n",
" optimizer='adam',\n",
" metrics=['accuracy'])"
]
},
{
"cell_type": "code",
"execution_count": 29,
"metadata": {},
"outputs": [
{
"ename": "NameError",
"evalue": "name 'X_train' is not defined",
"output_type": "error",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)",
"\u001b[1;32m<ipython-input-29-7db9323b7d77>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mmodel\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mfit\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mX_train\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mY_train_encoded\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mepochs\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;36m10\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mvalidation_split\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;36m0.3\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mbatch_size\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;36m10\u001b[0m \u001b[1;33m,\u001b[0m \u001b[0mverbose\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[1;31mNameError\u001b[0m: name 'X_train' is not defined"
]
}
],
"source": [
"model.fit(X_train, Y_train_encoded, epochs=10, validation_split=0.3, batch_size=10 , verbose=1)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#evaluating the model\n",
"model.evaluate(X_test, Y_test_encoded)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.4"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
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