――Je toucherai Python après un long moment. J'en suis accro maintenant, alors j'aimerais publier uniquement le contenu et les résultats de l'exécution et le mettre à jour au fur et à mesure de sa progression. --Enfin, précédemment, j'ai essayé de déplacer le modèle SSD par copier-coller, mais je veux pouvoir faire des choses en moi-même. .. Cette fois, le modèle VGG16 sera appliqué dans le modèle d'apprentissage en profondeur, mais il n'y en a pas beaucoup qui sont expliqués avec soin ce qui a été mis en œuvre à l'aide de TensorFlow, et le concept de ce modèle VGG16 est également dans le modèle SSD. Comme il est inclus, je l'ai essayé comme tremplin.
http://tensorflow.classcat.com/2016/10/18/tensorflow-vgg-model/
network.py
#!/usr/local/bin/python
# -*- coding: utf-8 -*-
import numpy as np
import tensorflow as tf
def vgg16(image, keep_prob):
def weight_variable(shape):
initial = tf.truncated_normal(shape, stddev=0.1)
return tf.Variable(initial)
def bias_variable(shape):
initial = tf.constant(0.1, shape=shape)
return tf.Variable(initial)
def conv2d(conv, weight):
return tf.nn.conv2d(conv, weight, strides=[1, 1, 1, 1], padding='SAME')
def max_pool_2x2(conv):
return tf.nn.max_pool(conv, ksize=[1, 2, 2, 1], strides=[1, 2, 2, 1], padding='SAME')
with tf.name_scope('conv1_1') as scope:
weight = weight_variable([3, 3, 3, 64])
bias = bias_variable([64])
conv = conv2d(image, weight)
out = tf.nn.bias_add(conv, bias)
conv1_1 = tf.nn.relu(out, name=scope)
with tf.name_scope('conv1_2') as scope:
weight = weight_variable([3, 3, 64, 64])
bias = bias_variable([64])
conv = conv2d(conv1_1, weight)
out = tf.nn.bias_add(conv, bias)
conv1_2 = tf.nn.relu(out, name=scope)
with tf.name_scope('pool1') as scope:
pool1 = max_pool_2x2(conv1_2)
with tf.name_scope('conv2_1') as scope:
weight = weight_variable([3, 3, 64, 128])
bias = bias_variable([128])
conv = conv2d(pool1, weight)
out = tf.nn.bias_add(conv, bias)
conv2_1 = tf.nn.relu(out, name=scope)
with tf.name_scope('conv2_2') as scope:
weight = weight_variable([3, 3, 128, 128])
bias = bias_variable([128])
conv = conv2d(conv2_1, weight)
out = tf.nn.bias_add(conv, bias)
conv2_2 = tf.nn.relu(out, name=scope)
with tf.name_scope('pool2') as scope:
pool2 = max_pool_2x2(conv2_2)
with tf.name_scope('conv3_1') as scope:
weight = weight_variable([3, 3, 128, 256])
bias = bias_variable([256])
conv = conv2d(pool2, weight)
out = tf.nn.bias_add(conv, bias)
conv3_1 = tf.nn.relu(out, name=scope)
with tf.name_scope('conv3_2') as scope:
weight = weight_variable([3, 3, 256, 256])
bias = bias_variable([256])
conv = conv2d(conv3_1, weight)
out = tf.nn.bias_add(conv, bias)
conv3_2 = tf.nn.relu(out, name=scope)
with tf.name_scope('conv3_3') as scope:
weight = weight_variable([3, 3, 256, 256])
bias = bias_variable([256])
conv = conv2d(conv3_2, weight)
out = tf.nn.bias_add(conv, bias)
conv3_3 = tf.nn.relu(out, name=scope)
with tf.name_scope('pool3') as scope:
pool3 = max_pool_2x2(conv3_3)
with tf.name_scope('conv4_1') as scope:
weight = weight_variable([3, 3, 256, 512])
bias = bias_variable([512])
conv = conv2d(pool3, weight)
out = tf.nn.bias_add(conv, bias)
conv4_1 = tf.nn.relu(out, name=scope)
with tf.name_scope('conv4_2') as scope:
weight = weight_variable([3, 3, 512, 512])
bias = bias_variable([512])
conv = conv2d(conv4_1, weight)
out = tf.nn.bias_add(conv, bias)
conv4_2 = tf.nn.relu(out, name=scope)
with tf.name_scope('conv4_3') as scope:
weight = weight_variable([3, 3, 512, 512])
bias = bias_variable([512])
conv = conv2d(conv4_2, weight)
out = tf.nn.bias_add(conv, bias)
conv4_3 = tf.nn.relu(out, name=scope)
with tf.name_scope('pool4') as scope:
pool4 = max_pool_2x2(conv4_3)
with tf.name_scope('conv5_1') as scope:
weight = weight_variable([3, 3, 512, 512])
bias = bias_variable([512])
conv = conv2d(pool4, weight)
out = tf.nn.bias_add(conv, bias)
conv5_1 = tf.nn.relu(out, name=scope)
with tf.name_scope('conv5_2') as scope:
weight = weight_variable([3, 3, 512, 512])
bias = bias_variable([512])
conv = conv2d(conv5_1, weight)
out = tf.nn.bias_add(conv, bias)
conv5_2 = tf.nn.relu(out, name=scope)
with tf.name_scope('conv5_3') as scope:
weight = weight_variable([3, 3, 512, 512])
bias = bias_variable([512])
conv = conv2d(conv5_2, weight)
out = tf.nn.bias_add(conv, bias)
conv5_3 = tf.nn.relu(out, name=scope)
with tf.name_scope('pool5') as scope:
pool5 = max_pool_2x2(conv5_3)
with tf.name_scope('fc6') as scope:
shape = int(np.prod(pool5.get_shape()[1:]))
weight = weight_variable([shape, 4096])
bias = bias_variable([4096])
pool5_flat = tf.reshape(pool5, [-1, shape])
fc6 = tf.nn.relu(tf.nn.bias_add(tf.matmul(pool5_flat, weight), bias))
# fc6_drop = tf.nn.dropout(fc6, keep_prob)
with tf.name_scope('fc7') as scope:
weight = weight_variable([4096, 4096])
bias = bias_variable([4096])
fc7 = tf.nn.relu(tf.nn.bias_add(tf.matmul(fc6, weight), bias))
# fc7_drop = tf.nn.dropout(fc7, keep_prob)
with tf.name_scope('fc8') as scope:
weight = weight_variable([4096, 3])
bias = bias_variable([3])
fc8 = tf.nn.bias_add(tf.matmul(fc7, weight), bias)
with tf.name_scope('softmax') as scope:
probs = tf.nn.softmax(fc8)
return probs
2017-08-01 17:39:33.518478: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations.
2017-08-01 17:39:33.518513: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations.
2017-08-01 17:39:33.518523: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX2 instructions, but these are available on your machine and could speed up CPU computations.
2017-08-01 17:39:33.518532: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use FMA instructions, but these are available on your machine and could speed up CPU computations.
step 0, training accuracy 0.588235
step 1, training accuracy 0.588235
step 2, training accuracy 0.588235
step 3, training accuracy 0.588235
step 4, training accuracy 0.588235
step 5, training accuracy 0.588235
step 6, training accuracy 0.588235
step 7, training accuracy 0.588235
«J'ai essayé de réduire le nombre de couches. → Pas de changement.
――J'ai changé les données d'entraînement. → Pas de changement.
―― La notation reste la même et je l'ai changée en couche CNN normale. → L'apprentissage s'est fait normalement.
(゚ д ゚)