modelConvert.m 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. function modelConvert(model, outname)
  2. %% script for converting Piotr's matlab model into YAML format
  3. outfile = fopen(outname, 'w');
  4. fprintf(outfile, '%%YAML:1.0\n\n');
  5. fprintf(outfile, ['options:\n'...
  6. ' numberOfTrees: 8\n'...
  7. ' numberOfTreesToEvaluate: 4\n'...
  8. ' selfsimilarityGridSize: 5\n'...
  9. ' stride: 2\n'...
  10. ' shrinkNumber: 2\n'...
  11. ' patchSize: 32\n'...
  12. ' patchInnerSize: 16\n'...
  13. ' numberOfGradientOrientations: 4\n'...
  14. ' gradientSmoothingRadius: 0\n'...
  15. ' regFeatureSmoothingRadius: 2\n'...
  16. ' ssFeatureSmoothingRadius: 8\n'...
  17. ' gradientNormalizationRadius: 4\n\n']);
  18. fprintf(outfile, 'childs:\n');
  19. printToYML(outfile, model.child', 0);
  20. fprintf(outfile, 'featureIds:\n');
  21. printToYML(outfile, model.fids', 0);
  22. fprintf(outfile, 'thresholds:\n');
  23. printToYML(outfile, model.thrs', 0);
  24. N = 1000;
  25. fprintf(outfile, 'edgeBoundaries:\n');
  26. printToYML(outfile, model.eBnds, N);
  27. fprintf(outfile, 'edgeBins:\n');
  28. printToYML(outfile, model.eBins, N);
  29. fclose(outfile);
  30. gzip(outname);
  31. end
  32. function printToYML(outfile, A, N)
  33. %% append matrix A to outfile as
  34. %% - [a11, a12, a13, a14, ..., a1n]
  35. %% - [a21, a22, a23, a24, ..., a2n]
  36. %% ...
  37. %%
  38. %% if size(A, 2) == 1, A is printed by N elemnent per row
  39. if (length(size(A)) ~= 2)
  40. error('printToYML: second-argument matrix should have two dimensions');
  41. end
  42. if (size(A,2) ~= 1)
  43. for i=1:size(A,1)
  44. fprintf(outfile, ' - [');
  45. fprintf(outfile, '%d,', A(i, 1:end-1));
  46. fprintf(outfile, '%d]\n', A(i, end));
  47. end
  48. else
  49. len = length(A);
  50. for i=1:ceil(len/N)
  51. first = (i-1)*N + 1;
  52. last = min(i*N, len) - 1;
  53. fprintf(outfile, ' - [');
  54. fprintf(outfile, '%d,', A(first:last));
  55. fprintf(outfile, '%d]\n', A(last + 1));
  56. end
  57. end
  58. fprintf(outfile, '\n');
  59. end