bytedeco / sample-projects

Sample project files for JavaCPP, JavaCPP Presets, and JavaCV
219 stars 174 forks source link

Make a mean.binaryproto from java (Question) #28

Closed OleksandrGrument closed 3 years ago

OleksandrGrument commented 6 years ago

Hello, i'm trying to implement in java deepdream notebook from python
https://github.com/google/deepdream/blob/master/dream.ipynb

in python there are code that generating mean.binaryproto from values.

mean = np.float32([104.0, 116.0, 122.0]), # ImageNet mean, training set

I have add a library java variant of Nyphy called Nd4j.

Tryed to generate the mean file with code bellow.

  `     
    String meanFile = caffeConfigRoot + "mean.binaryproto";

    double[] meanTrainingSet = {104.0, 116.0, 122.0};

    INDArray indArray = Nd4j.create(meanTrainingSet);

    try (DataOutputStream dos = new DataOutputStream(new FileOutputStream(new File(meanFile)))){

        Nd4j.write(indArray, dos);

    }`

And i'm getting the error.

[blob.cpp:496] Check failed: count_ == proto.data_size() (1 vs. 0)

in this piece of code

`

BlobProto blobProto = new BlobProto();

ReadProtoFromBinaryFileOrDie(meanFile, blobProto);

FloatBlob meanBlob = new FloatBlob();

meanBlob.FromProto(blobProto);

`

Maybe is there some code how to generate this mean file from java or the problem not in mean file and it correct.

Anyway I'm trying to find a solution but there are a few information about this. Any help would be appreciated. Thank you;

saudet commented 6 years ago

It would probably be easier to find a way to write it with Caffe. We could then be sure the data format is compatible. Any ideas @cypof?

OleksandrGrument commented 6 years ago

As you mentioned I created a .binaryproto file from notebook and it was different than i created before. I wish someone knew better way to generate .binaryproto from java code, but for now it enough.

Also i found an strange check in example code in Classifier class , there is checking of channels, and it was trowing me and exceptions, but i commented this piece of code and build was succesfull and it is strange.

if (numChannels != inputLayer.channels()) { throw new IllegalStateException("Number of channels of mean file doesn't match input layer"); }

Thanks for help.

saudet commented 6 years ago

Strange, would you know @Undin ?

Undin commented 6 years ago

I don't really know but this sample is just java version of the original sample. And it has this check too.