0

I want to train a net to recognize some RGB in image. (input: 256X256 images and some RGB value).

I wrote a script that creates HDF5 file for float multi-labels:

import h5py, os
import caffe
import numpy as np

SIZE = 256 # images size
with open( '/home/path/images ):
    lines = T.readlines()

X = np.zeros( (len(lines), SIZE, SIZE, 3), dtype='f4' )
r = np.zeros( (len(lines),1), dtype='f4' )
g = np.zeros( (len(lines),1), dtype='f4' )
b = np.zeros( (len(lines),1), dtype='f4' )

for i,l in enumerate(lines):
    sp = l.split(' ')
    img = caffe.io.load_image( sp[0] )
#    img = caffe.io.resize( img, (3, SIZE, SIZE) ) # resize to fixed $
    print img
    X[i] = img
#    print X[i]
    r[i] = float(sp[1])
    g[i] = float(sp[2])
    b[i] = float(sp[3])
    print "R" + str(r[i]) + "G" + str(g[i]) + "B" + str(b[i])
with h5py.File('/home/path/train.h5','$
    H.create_dataset('X', data=X)
    H.create_dataset('r', data=r)
    H.create_dataset('g', data=g)
    H.create_dataset('b', data=b) 

with open('/home/path/train_h5_list.tx$
    L.write( 'train.h5' ) # list all h5 files

Im using a multi-label regression net. when i run TRAIN on this net with my dataset (HDF5) i got this error:

name: "FKPReg"
state {
  phase: TRAIN
}
layer {
  name: "fkp"
  type: "HDF5Data"
  top: "data"
  top: "label"
  include {
    phase: TRAIN
  }
  hdf5_data_param {
    source: "/home/path/train_h5_list.txt"
    batch_size: 64
  }
}
layer {
  name: "conv1"
  type: "Convolution"
  bottom: "data"
  top: "conv1"
  convolution_param {
    num_output: 32
    kernel_size: 11
    stride: 2
    bias_filler {
      type: "constant"
      value: 0.1
    }
  }
}
layer {
  name: "relu2"
  type: "ReLU"
  bottom: "conv1"
  top: "conv1"
}
layer {
  name: "pool1"
  type: "Pooling"
  bottom: "conv1"
  top: "pool1"
  pooling_param {
    pool: MAX
    kernel_size: 2
    stride: 2
  }
}
layer {
  name: "conv2"
  type: "Convolution"
  bottom: "pool1"
  top: "conv2"
  convolution_param {
    num_output: 64
    pad: 2
    kernel_size: 7
    group: 2
    bias_filler {
      type: "constant"
      value: 0.1
    }
  }
}
layer {
  name: "relu2"
  type: "ReLU"
  bottom: "conv2"
  top: "conv2"
}
layer {
  name: "pool2"
  type: "Pooling"
  bottom: "conv2"
  top: "pool2"
  pooling_param {
    pool: MAX
    kernel_size: 2
    stride: 2
  }
}
layer {
  name: "norm2"
  type: "LRN"
  bottom: "pool2"
  top: "norm2"
  lrn_param {
    local_size: 3
    alpha: 5e-05
    beta: 0.75
    norm_region: WITHIN_CHANNEL
  }
}
layer {
  name: "conv3"
  type: "Convolution"
  bottom: "norm2"
  top: "conv3"
  convolution_param {
    num_output: 32
    pad: 1
    kernel_size: 5
    bias_filler {
      type: "constant"
      value: 0.1
    }
  }
}
layer {
  name: "relu3"
  type: "ReLU"
  bottom: "conv3"
  top: "conv3"
}
layer {
  name: "conv4"
  type: "Convolution"
  bottom: "conv3"
  top: "conv4"
  convolution_param {
    num_output: 64
    pad: 1
    kernel_size: 5
    bias_filler {
      type: "constant"
      value: 0.1
    }
  }
}
layer {
  name: "relu4"
  type: "ReLU"
  bottom: "conv4"
  top: "conv4"
}
layer {
  name: "conv5"
  type: "Convolution"
  bottom: "conv4"
  top: "conv5"
  convolution_param {
    num_output: 32
    pad: 1
    kernel_size: 5
    bias_filler {
      type: "constant"
      value: 0.1
    }
  }
}
layer {
  name: "relu5"
  type: "ReLU"
  bottom: "conv5"
  top: "conv5"
}
layer {
  name: "pool5"
  type: "Pooling"
  bottom: "conv5"
  top: "pool5"
  pooling_param {
    pool: MAX
    kernel_size: 4
    stride: 2
  }
}
layer {
  name: "drop0"
  type: "Dropout"
  bottom: "pool5"
  top: "pool5"
  dropout_param {
    dropout_ratio: 0.5
  }
}
layer {
  name: "ip1"
  type: "InnerProduct"
  bottom: "pool5"
  top: "ip1"
  inner_product_param {
    num_output: 100
    bias_filler {
      type: "constant"
      value: 0.1
    }
  }
}
layer {
  name: "relu4"
  type: "ReLU"
  bottom: "ip1"
  top: "ip1"
}
layer {
  name: "drop1"
  type: "Dropout"
  bottom: "ip1"
  top: "ip1"
  dropout_param {
    dropout_ratio: 0.5
  }
}
layer {
  name: "ip2"
  type: "InnerProduct"
  bottom: "ip1"
  top: "ip2"
  inner_product_param {
    num_output: 3
    bias_filler {
      type: "constant"
      value: 0.1
    }
  }
}
layer {
  name: "relu22"
  type: "ReLU"
  bottom: "ip2"
  top: "ip2"
}
layer {
  name: "loss"
  type: "EuclideanLoss"
  bottom: "ip2"
  bottom: "label"
  top: "loss"
}
I1106 11:47:52.235343 28083 layer_factory.hpp:74] Creating layer fkp
I1106 11:47:52.235384 28083 net.cpp:90] Creating Layer fkp
I1106 11:47:52.235410 28083 net.cpp:368] fkp -> data
I1106 11:47:52.235443 28083 net.cpp:368] fkp -> label
I1106 11:47:52.235481 28083 net.cpp:120] Setting up fkp
I1106 11:47:52.235496 28083 hdf5_data_layer.cpp:80] Loading list of HDF5 filenames from: /home/path/train_h5_list.txt
I1106 11:47:52.235568 28083 hdf5_data_layer.cpp:94] Number of HDF5 files: 1
HDF5-DIAG: Error detected in HDF5 (1.8.11) thread 140703305845312:
  #000: ../../../src/H5F.c line 1586 in H5Fopen(): unable to open file
    major: File accessibilty
    minor: Unable to open file
  #001: ../../../src/H5F.c line 1275 in H5F_open(): unable to open file: time = Sun Nov  6 11:47:52 2016
, name = 'train.h5', tent_flags = 0
    major: File accessibilty
    minor: Unable to open file
  #002: ../../../src/H5FD.c line 987 in H5FD_open(): open failed
    major: Virtual File Layer
    minor: Unable to initialize object
  #003: ../../../src/H5FDsec2.c line 343 in H5FD_sec2_open(): unable to open file: name = 'train.h5', errno = 2, error message = 'No such file or directory', flags = 0, o_flags = 0
    major: File accessibilty
    minor: Unable to open file
F1106 11:47:52.236398 28083 hdf5_data_layer.cpp:32] Failed opening HDF5 file: train.h5
*** Check failure stack trace: ***
    @     0x7ff809dfcdaa  (unknown)
    @     0x7ff809dfcce4  (unknown)
    @     0x7ff809dfc6e6  (unknown)
    @     0x7ff809dff687  (unknown)
    @     0x7ff80a194406  caffe::HDF5DataLayer<>::LoadHDF5FileData()
    @     0x7ff80a192c98  caffe::HDF5DataLayer<>::LayerSetUp()
    @     0x7ff80a173be3  caffe::Net<>::Init()
    @     0x7ff80a175952  caffe::Net<>::Net()
    @     0x7ff80a15bbf0  caffe::Solver<>::InitTrainNet()
    @     0x7ff80a15cbc3  caffe::Solver<>::Init()
    @     0x7ff80a15cd96  caffe::Solver<>::Solver()
    @           0x40c5d0  caffe::GetSolver<>()
    @           0x406611  train()
    @           0x404bb1  main
    @     0x7ff80930ef45  (unknown)
    @           0x40515d  (unknown)
    @              (nil)  (unknown)
Aborted (core dumped)

What am I doing wrong? thanks

Shai
  • 111,146
  • 38
  • 238
  • 371
Z.Kal
  • 426
  • 4
  • 18

1 Answers1

0

A few comments

  1. caffe.io.resize( img, (3, SIZE, SIZE) ) - this is WRONG.
    you need to resize to (SIZE, SIZE) and the transpose to (3, SIZE, SIZE). resize should affect only the spatial dimensions of the image, and transpose should take care of arranging the channel dimension before height and width.
    Consequently, the shape of X should be (len(lines), 3, SIZE, SIZE).

  2. If your HDF5 file has datasets X, r, g and b, then your "HDF5Data" layer can have "top"s "X", "r", "g" and/or "b". You cannot have "data" or "label" as "top"s since there are no such datasets in the input hdf5 file.

  3. The error message you got states (quite clearly) that

    error message = 'No such file or directory'

    This usually means that train.h5 is not in the search path.
    Try writing full path to /home/path/train_h5_list.txt.

Shai
  • 111,146
  • 38
  • 238
  • 371
  • thank for the comment. I tried to change the "data" / "label" to "X"/ "r".. but it dosn't work. what should I do? – Z.Kal Nov 06 '16 at 13:10
  • it might be that the `h5` file itself is corrupted. What do you get from `h5ls` in shell? – Shai Nov 06 '16 at 13:10
  • i write to the `h5` file (from `.txt` file) an numpy array (image matrix) and 3 values of RGB. maybe the problem in the dataset it because of the `[` `]` of the array? – Z.Kal Nov 06 '16 at 13:26
  • I wrote the full path but still I got this message: `Check failed: H5LTfind_dataset(file_id, dataset_name_) Failed to find HDF5 dataset data ` – Z.Kal Nov 06 '16 at 13:28
  • @Z.Kal because you do not have dataset `'data'` only `'X'`, `'r'`, `'g'` and `'b'`... – Shai Nov 06 '16 at 13:29
  • so what do you think I should do? – Z.Kal Nov 06 '16 at 13:30
  • @Z.Kal follow the three steps in the answer. – Shai Nov 06 '16 at 13:31
  • i did the first one, but how can I change `label` with `X` / `r` `g`? I tried to change it in the `.prototxt` file but it dosn't work. shoul I build the `.h5` file differently? – Z.Kal Nov 06 '16 at 13:37
  • I changed `X` -> `data` and `[r,g,b]` -> `label`, and now it shows me this error: `F1107 07:43:36.519747 3054 hdf5_data_layer.cpp:54] Check failed: hdf_blobs_[i]->shape(0) == num (3 vs. 10464)` – Z.Kal Nov 07 '16 at 07:46
  • @Z.Kal you are making a mess of the `shape`s and names of your datasets/`"top"`s. please follow *carefully* [this answer](http://stackoverflow.com/a/31808324/1714410) – Shai Nov 07 '16 at 07:51