Перейти к содержимому
Compvision.ru
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

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

Поделиться сообщением


Ссылка на сообщение
Поделиться на других сайтах

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"

Поделиться сообщением


Ссылка на сообщение
Поделиться на других сайтах

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

Поделиться сообщением


Ссылка на сообщение
Поделиться на других сайтах
53 минуты назад, Smorodov сказал:

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

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

Поделиться сообщением


Ссылка на сообщение
Поделиться на других сайтах

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

Поделиться сообщением


Ссылка на сообщение
Поделиться на других сайтах

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

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

 

Поделиться сообщением


Ссылка на сообщение
Поделиться на других сайтах

Создайте учётную запись или войдите для комментирования

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

Создать учётную запись

Зарегистрируйтесь для создания учётной записи. Это просто!

Зарегистрировать учётную запись

Войти

Уже зарегистрированы? Войдите здесь.

Войти сейчас


  • Сейчас на странице   0 пользователей

    Нет пользователей, просматривающих эту страницу

×