Jump to content
Compvision.ru
Sign in to follow this  
Smorodov

Python layer не хочет создаваться.

Recommended Posts

Пытаюсь соорудить слой для рандомного поворота обучающих пар

import caffe
import random
import os
import numpy as np 
from scipy import ndimage

def doAugmentation(img,mask):
    print('In Augmentation')
    ang=random.uniform(-30,30)
    return [ndimage.rotate(img, ang, reshape=False),ndimage.rotate(mask, ang, reshape=False)]

class RotationLayer(caffe.Layer):
    def setup(self, bottom, top):
        print('In Setup')
        #assert len(bottom) == 2, 'requires 2 layer.bottom'
        #assert bottom[0].data.ndim >= 3, 'requires image data'
        #assert bottom[1].data.ndim >= 3, 'requires image data'
        #assert len(top) == 2, 'requires 2 layer.top'

    def reshape(self, bottom, top):
        # Copy shape from bottom
        print('In Reshape')
        #top[0].reshape(*bottom[0].data.shape)
        #top[1].reshape(*bottom[1].data.shape)

    def forward(self, bottom, top):
        # Copy all of the data
        print('In Forward')
        #top[0].data[...] = bottom[0].data[...]
        #top[1].data[...] = bottom[1].data[...]
        #for ii in xrange(0, top[0].data.shape[0]):
        #    [top[0].data[ii, :, :, :],top[1].data[ii, :, :, :]] = doAugmentation(top[0].data[ii, :, :, :],top[1].data[ii, :, :, :])

    def backward(self, top, propagate_down, bottom):
        pass

Уже оставил только логи, но и они не выводятся.

Вставляю в prototxt это так:

# data layer
layer {
  name: "data"
  type: "Data"
  top: "data"
  include {
    phase: TRAIN
  }
  data_param {
    batch_size: 1
    backend: LMDB
  }
    transform_param {
    mean_value: 104.008
    mean_value: 116.669
    mean_value: 122.675
    mirror: true
  }
}
layer {
  name: "label"
  type: "Data"
  top: "label"
  include {
    phase: TRAIN
  }
  data_param {
    batch_size: 1
    backend: LMDB
  }

}
layer {
  name: "data"
  type: "Data"
  top: "data"
  include {
    phase: TEST
  }
  data_param {
    batch_size: 1
    backend: LMDB
  }
      transform_param {
    mean_value: 104.008
    mean_value: 116.669
    mean_value: 122.675
    mirror: true
  }
}
layer {
  name: "label"
  type: "Data"
  top: "label"
  include {
    phase: TEST
  }
  data_param {
    batch_size: 1
    backend: LMDB
  }

}

layer {
  # Use Power layer for input scaling
  name: "scale"
  bottom: "data"
  top: "scaled"
  type: "Power"
  power_param {
    scale: 0.00390625
  }
}

layer {
  type: 'Python'
  name: 'RotationLayer'
  top: 'scaled'
  top: 'label'
  bottom: 'scaled'
  bottom: 'label'
  python_param {
    module: 'rotation_layer'
    layer: 'RotationLayer'
  }
        exclude {
    stage: "deploy"
  }
}

 

В DIGITS, в Python Layers путь к питонскому исходнику указал.

 

Получаю ERROR: error code 1

и вывод:

Top shape: 1 3 800 600 (1440000)
Top shape: 1 3 800 600 (1440000)
Memory required for data: 17280000
Creating layer label
Creating Layer label
label -> label
Opened lmdb /home/andrey/digits_jobs/20170904-201718-d3ff/train_db/labels
ReshapePrefetch 1, 1, 800, 600
output data size: 1,1,800,600
Setting up label
Top shape: 1 1 800 600 (480000)
Memory required for data: 19200000
Creating layer scale
Creating Layer scale
scale <- data_data_0_split_0
scale -> scaled
Setting up scale
Top shape: 1 3 800 600 (1440000)
Memory required for data: 24960000
Creating layer RotationLayer

UPD:

Запихнул в caffe/python который есть в PYTHONPATH, теперь  ERROR: error code -6

Мне питонские слои пока не доводилось использовать, что может быть не так ?

Share this post


Link to post
Share on other sites

error 1 всегда преследует созданный пользователем python файл. В данном случае функцию doAugmentation лучше поместить в класс RotationLayer

 

import random

import numpy as np
import caffe


class RotationLayer(caffe.Layer):
    def setup(self, bottom, top):
        print('In Setup')
        #assert len(bottom) == 2, 'requires 2 layer.bottom'
        #assert bottom[0].data.ndim >= 3, 'requires image data'
        #assert bottom[1].data.ndim >= 3, 'requires image data'
        #assert len(top) == 2, 'requires 2 layer.top'

    def reshape(self, bottom, top):
        # Copy shape from bottom
        print('In Reshape')
        #top[0].reshape(*bottom[0].data.shape)
        #top[1].reshape(*bottom[1].data.shape)

    def forward(self, bottom, top):
        # Copy all of the data
        print('In Forward')
        #top[0].data[...] = bottom[0].data[...]
        #top[1].data[...] = bottom[1].data[...]
        #for ii in xrange(0, top[0].data.shape[0]):
        #    [top[0].data[ii, :, :, :],top[1].data[ii, :, :, :]] = doAugmentation(top[0].data[ii, :, :, :],top[1].data[ii, :, :, :])

    def backward(self, top, propagate_down, bottom):
        pass

    def doAugmentation(self):
        print("aug")
        #print('In Augmentation')
        #ang=random.uniform(-30,30)
        #return [ndimage.rotate(img, ang, reshape=False),ndimage.rotate(mask, ang, reshape=False)]

Если используешь DIGITS в определении модели можно указать module: "digits_python_layers"

Share this post


Link to post
Share on other sites

Не, дохлый номер, ошибка 1 ушла, теперь ошибка -6. Чего-то я здесь недопонимаю.

Share this post


Link to post
Share on other sites
53 минуты назад, Smorodov сказал:

Не, дохлый номер, ошибка 1 ушла, теперь ошибка -6. Чего-то я здесь недопонимаю.

В digits зашло без ошибок 

Share this post


Link to post
Share on other sites

Нашел причину в логах caffe, версия protobuf ему не нравится. Установлена 2.6.1, а он хочет 3.1.

Share this post


Link to post
Share on other sites

Работающая версия питонского слоя для поворота изображения и маски:

import caffe
import random
import numpy as np 
from scipy import ndimage

def doAugmentation(img,mask):
    #print("aug")
    #print('In Augmentation')
    ang=random.uniform(-30,30)
    return [ndimage.rotate(img, ang, reshape=False, axes=(1,2)),ndimage.rotate(mask, ang, reshape=False,axes=(1,2))]

class RotationLayer(caffe.Layer):

    
    def setup(self, bottom, top):
        #print('In Setup')
        assert len(bottom) == 2, 'requires 2 layer.bottom'
        assert bottom[0].data.ndim >= 3, 'requires image data'
        assert bottom[1].data.ndim >= 3, 'requires image data'
        assert len(top) == 2, 'requires 2 layer.top'

    def reshape(self, bottom, top):
        # Copy shape from bottom
        #print('In Reshape')
        top[0].reshape(*bottom[0].data.shape)
        top[1].reshape(*bottom[1].data.shape)

    def forward(self, bottom, top):
        # Copy all of the data
        #print('In Forward')
        top[0].data[...] = bottom[0].data[...]
        top[1].data[...] = bottom[1].data[...]
        
        for ii in xrange(0, top[0].data.shape[0]):
            top[0].data[ii, :, :, :]=bottom[0].data[...]
            top[1].data[ii, :, :, :]=bottom[1].data[...]            
            [top[0].data[ii, :, :, :],top[1].data[ii, :, :, :]] = doAugmentation(top[0].data[ii, :, :, :],top[1].data[ii, :, :, :])

    def backward(self, top, propagate_down, bottom):
        pass

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×