def build_model(self): self.conv1_1 = ops.conv('conv1_1', self.x, 32, kernel_size=[3, 3], stride=[1, 1, 1, 1], padding='SAME', is_training=self.is_training) self.conv1_2 = ops.conv('conv1_2', self.conv1_1, 32, kernel_size=[3, 3], stride=[1, 1, 1, 1], padding='SAME', is_training=self.is_training) self.pool1 = ops.pool('pool1', self.conv1_2, kernel=[1, 2, 2, 1], stride=[1, 2, 2, 1], is_max_pool=True) self.pool1_norm1 = ops.lrn('pool1_norm1', self.pool1) self.conv2_1 = ops.conv('conv2_1', self.pool1_norm1, 64, kernel_size=[5, 5], stride=[1, 1, 1, 1], padding='SAME', is_training=self.is_training) self.conv2_2 = ops.conv('conv2_2', self.conv2_1, 64, kernel_size=[5, 5], stride=[1, 1, 1, 1], padding='SAME', is_training=self.is_training) self.batch_norm1 = ops.batch_normalization('batch_norm1', self.conv2_2, is_training=self.is_training) self.pool2 = ops.pool('pool2', self.batch_norm1, kernel=[1, 2, 2, 1], stride=[1, 2, 2, 1], is_max_pool=True) self.conv3_1 = ops.conv('conv3_1', self.pool2, 64, kernel_size=[3, 3], stride=[1, 1, 1, 1], padding='SAME', is_training=self.is_training) self.conv3_2 = ops.conv('conv3_2', self.conv3_1, 64, kernel_size=[3, 3], stride=[1, 1, 1, 1], padding='SAME', is_training=self.is_training) self.batch_norm2 = ops.batch_normalization('batch_norm2', self.conv3_2, is_training=self.is_training) self.pool3 = ops.pool('pool3', self.batch_norm2, kernel=[1, 2, 2, 1], stride=[1, 2, 2, 1], is_max_pool=True) self.fc1 = ops.fc('fc1', self.pool3, out_nodes=1024) self.batch_norm3 = ops.batch_normalization('batch_norm3', self.fc1, is_training=self.is_training) self.dropout1 = ops.dropout(self.batch_norm3, 0.50, is_training=self.is_training) self.fc2 = ops.fc('fc2', self.dropout1, out_nodes=512) self.batch_norm4 = ops.batch_normalization('batch_norm4', self.fc2, is_training=self.is_training) self.fc3 = ops.fc('fc3', self.batch_norm4, out_nodes=256) self.dropout3 = ops.dropout(self.fc3, 0.50, is_training=self.is_training) self.logits = ops.fc('fc_output', self.dropout3, out_nodes=self.config.n_classes, act_type=None) loss = self.cal_loss(self.logits, self.y) accuracy = self.cal_accuracy(self.logits, self.y) tf.summary.scalar('loss', loss) tf.summary.scalar('accuracy', accuracy) # train_op = self.optimize() return loss, accuracy
def res_net(self): conv1 = ops.conv('conv1', self.x, 16, kernel_size=[7, 7], stride=[1, 1, 1, 1], is_training=self.is_training) conv2 = ops.conv('conv2', conv1, 32, kernel_size=[3, 3], stride=[1, 1, 1, 1], is_training=self.is_training) res1 = ops.residual_layer('residual_1', conv2, 32) pool1 = ops.pool('pool1', res1) res2 = ops.residual_layer('residual_2', pool1, 32) pool2 = ops.pool('pool2', res2) res3 = ops.residual_layer('residual_3', pool2, 32) conv3 = ops.conv('conv3', res3, 64, kernel_size=[3, 3], stride=[1, 1, 1, 1], is_training=self.is_training) pool3 = ops.pool('pool3', conv3) lrn = ops.lrn('lrn1', pool3) dropout1 = ops.dropout(lrn, 0.50, is_training=self.is_training) fc1 = ops.fc('fc1', dropout1, out_nodes=128) dropout2 = ops.dropout(fc1, 0.40, is_training=self.is_training) batch_norm1 = ops.batch_normalization('batch_norm1', dropout2, is_training=self.is_training) fc2 = ops.fc('fc2', batch_norm1, out_nodes=512) batch_norm2 = ops.batch_normalization('batch_norm4', fc2, is_training=self.is_training) self.logits = ops.fc('output_layer', batch_norm2, out_nodes=self.config.n_classes, act_type=None) loss = self.cal_loss(self.logits, self.y) accuracy = self.cal_accuracy(self.logits, self.y) tf.summary.scalar('loss', loss) tf.summary.scalar('accuracy', accuracy) # train_op = self.optimize() return loss, accuracy
def one_con_model(self): conv1_1 = ops.conv('conv1_1', self.x, 16, kernel_size=[5, 5], stride=[1, 1, 1, 1], is_training=self.is_training) conv1_2 = ops.conv('conv1_2', conv1_1, 16, kernel_size=[5, 5], stride=[1, 1, 1, 1], is_training=self.is_training) pool1 = ops.pool('pool1', conv1_2, kernel=[1, 2, 2, 1], stride=[1, 2, 2, 1], is_max_pool=True) lnr1 = ops.lrn('lrn1', pool1) conv2_1 = ops.conv('conv2_1', pool1, 32, kernel_size=[3, 3], stride=[1, 1, 1, 1], is_training=self.is_training) conv2_2 = ops.conv('conv2_2', conv2_1, 32, kernel_size=[3, 3], stride=[1, 1, 1, 1], is_training=self.is_training) lnr2 = ops.lrn('lrn2', conv2_2) concat1 = ops.layer_concat('concat1', [lnr1, lnr2]) pool2 = ops.pool('pool2', concat1, kernel=[1, 2, 2, 1], stride=[1, 2, 2, 1], is_max_pool=True) conv3_1 = ops.conv('conv3_1', pool2, 64, kernel_size=[3, 3], stride=[1, 1, 1, 1], is_training=self.is_training) conv3_2 = ops.conv('conv3_2', conv3_1, 64, kernel_size=[3, 3], stride=[1, 1, 1, 1], is_training=self.is_training) pool3 = ops.pool('pool3', conv3_2, kernel=[1, 2, 2, 1], stride=[1, 2, 2, 1], is_max_pool=True) lnr3 = ops.lrn('lrn3', pool3) dropout1 = ops.dropout(lnr3, 0.60, is_training=self.is_training) fc1 = ops.fc('fc1', dropout1, out_nodes=128) dropout2 = ops.dropout(fc1, 0.40, is_training=self.is_training) batch_norm1 = ops.batch_normalization('batch_norm1', dropout2, is_training=self.is_training) fc2 = ops.fc('fc2', batch_norm1, out_nodes=512) batch_norm2 = ops.batch_normalization('batch_norm4', fc2, is_training=self.is_training) self.logits = ops.fc('output_layer', batch_norm2, out_nodes=self.config.n_classes, act_type=None) loss = self.cal_loss(self.logits, self.y) accuracy = self.cal_accuracy(self.logits, self.y) tf.summary.scalar('loss', loss) tf.summary.scalar('accuracy', accuracy) # train_op = self.optimize() return loss, accuracy
def batch_model(self): re_input = tf.image.resize_nearest_neighbor(self.x, size=(64, 64)) conv1_1 = ops.conv('conv1_1', re_input, 64, kernel_size=[5, 5], stride=[1, 1, 1, 1], padding='SAME', is_training=self.is_training) conv1_2 = ops.conv('conv1_2', conv1_1, 64, kernel_size=[5, 5], stride=[1, 1, 1, 1], padding='SAME', is_training=self.is_training) bn1_1 = ops.batch_normalization('bn1_1', conv1_2, self.is_training) pool1_1 = ops.pool('pool1_1', bn1_1) dropout1 = ops.dropout(pool1_1, 0.5, is_training=self.is_training) conv2_1 = ops.conv('conv2_1', dropout1, 128, kernel_size=[3, 3], stride=[1, 1, 1, 1], padding='SAME', is_training=self.is_training) bn2_1 = ops.batch_normalization('bn2_1', conv2_1, self.is_training) conv2_2 = ops.conv('conv2_2', bn2_1, 128, kernel_size=[3, 3], stride=[1, 1, 1, 1], padding='SAME', is_training=self.is_training) bn2_2 = ops.batch_normalization('bn2_2', conv2_2, self.is_training) conv2_3 = ops.conv('conv2_3', bn2_2, 128, kernel_size=[3, 3], stride=[1, 1, 1, 1], padding='SAME', is_training=self.is_training) bn2_3 = ops.batch_normalization('bn2_3', conv2_3, self.is_training) pool2_1 = ops.pool('pool2_1', bn2_3) dropout2 = ops.dropout(pool2_1, 0.5, is_training=self.is_training) conv3_1 = ops.conv('conv3_1', dropout2, 256, kernel_size=[3, 3], stride=[1, 1, 1, 1], padding='SAME', is_training=self.is_training) bn3_1 = ops.batch_normalization('bn3_1', conv3_1, self.is_training) conv3_2 = ops.conv('conv3_2', bn3_1, 256, kernel_size=[3, 3], stride=[1, 1, 1, 1], padding='SAME', is_training=self.is_training) bn3_2 = ops.batch_normalization('bn3_2', conv3_2, self.is_training) conv3_3 = ops.conv('conv3_3', bn3_2, 256, kernel_size=[3, 3], stride=[1, 1, 1, 1], padding='SAME', is_training=self.is_training) bn3_3 = ops.batch_normalization('bn3_3', conv3_3, self.is_training) pool3_1 = ops.pool('pool3_1', bn3_3) dropout3 = ops.dropout(pool3_1, 0.5, is_training=self.is_training) conv4_1 = ops.conv('conv4_1', dropout3, 256, kernel_size=[3, 3], stride=[1, 1, 1, 1], padding='SAME', is_training=self.is_training) bn4_1 = ops.batch_normalization('bn4_1', conv4_1, self.is_training) conv4_2 = ops.conv('conv4_2', bn4_1, 256, kernel_size=[3, 3], stride=[1, 1, 1, 1], padding='SAME', is_training=self.is_training) bn4_2 = ops.batch_normalization('bn4_2', conv4_2, self.is_training) conv4_3 = ops.conv('conv4_3', bn4_2, 256, kernel_size=[3, 3], stride=[1, 1, 1, 1], padding='SAME', is_training=self.is_training) bn4_3 = ops.batch_normalization('bn4_3', conv4_3, self.is_training) pool4_1 = ops.pool('pool4_1', bn4_3) dropout4 = ops.dropout(pool4_1, 0.5, is_training=self.is_training) fc1 = ops.fc('fc1', dropout4, out_nodes=512) dropout_f1 = ops.dropout(fc1, 0.50, is_training=self.is_training) fc2 = ops.fc('fc2', dropout_f1, out_nodes=256) dropout_f2 = ops.dropout(fc2, 0.50, is_training=self.is_training) fc3 = ops.fc('fc3', dropout_f2, out_nodes=64) dropout_f3 = ops.dropout(fc3, 0.50, is_training=self.is_training) self.logits = ops.fc('output_layer', dropout_f3, out_nodes=self.config.n_classes, act_type=None) loss = self.cal_loss(self.logits, self.y) accuracy = self.cal_accuracy(self.logits, self.y) tf.summary.scalar('loss', loss) tf.summary.scalar('accuracy', accuracy) return loss, accuracy