read .yml files in matlab issue - matlab

For my project I want to read yml file in matlab using YAMLMatlab. My .yml files look like this. I am ust showing a part of .yml file. My file is around 29 MB.
%YAML:1.0
Block size: [ 16, 16 ]
Block stride: [ 8, 8 ]
Cell size: [ 8, 8 ]
block hist size: 36
block per img: [ 63, 63 ]
Total elements in array: 142884
nbins: 9
Scale: 1.
Level: 0
Width: 512
Height: 512
features:
- 1.5302167832851410e-01
- 1.0552208870649338e-01
- 1.6659785807132721e-01
- 2.3539969325065613e-01
- 2.0810306072235107e-01
- 1.2627227604389191e-01
- 8.0759152770042419e-02
- 6.4930714666843414e-02
- 6.1364557594060898e-02
- 2.1614919602870941e-01
- 1.4714729785919189e-01
While reading .yml file I got the following error.
Error using ReadYamlRaw>load_yaml (line 78)
Java exception occurred:
java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copyOf(Unknown Source)
at java.lang.AbstractStringBuilder.expandCapacity(Unknown Source)
at java.lang.AbstractStringBuilder.ensureCapacityInternal(Unknown Source)
at java.lang.AbstractStringBuilder.append(Unknown Source)
at java.lang.StringBuilder.append(Unknown Source)
at org.yaml.snakeyaml.reader.StreamReader.<init>(StreamReader.java:51)
at org.yaml.snakeyaml.Yaml.load(Yaml.java:399)
Error in ReadYamlRaw (line 42)
result = load_yaml(filename, nosuchfileaction, treatasdata);
Error in ReadYaml (line 48)
ry = ReadYamlRaw(filename, 0, nosuchfileaction, treatasdata);
Error in untitled (line 2)
YamlStruct = ReadYaml(yaml_file);
I believe this error is due to large file size as I can read simple .yml file. Can someone help me to resolve this error. I have also read this post.
P.S: Here is .yml file
EDIT:
It works with below answer but I got the following error now. Once I remover %YAML:1.0. It works fine.
Error using ReadYamlRaw>load_yaml (line 78)
Java exception occurred:
while scanning a directive
in "<string>", line 1, column 1:
%YAML:1.0
^
expected alphabetic or numeric character, but found :(58)
in "<string>", line 1, column 6:
%YAML:1.0
^
at org.yaml.snakeyaml.scanner.ScannerImpl.scanDirectiveName(ScannerImpl.java:1028)
at org.yaml.snakeyaml.scanner.ScannerImpl.scanDirective(ScannerImpl.java:990)
at org.yaml.snakeyaml.scanner.ScannerImpl.fetchDirective(ScannerImpl.java:534)
at org.yaml.snakeyaml.scanner.ScannerImpl.fetchMoreTokens(ScannerImpl.java:251)
at org.yaml.snakeyaml.scanner.ScannerImpl.checkToken(ScannerImpl.java:179)
at org.yaml.snakeyaml.parser.ParserImpl$ParseImplicitDocumentStart.produce(ParserImpl.java:198)
at org.yaml.snakeyaml.parser.ParserImpl.peekEvent(ParserImpl.java:161)
at org.yaml.snakeyaml.parser.ParserImpl.checkEvent(ParserImpl.java:146)
at org.yaml.snakeyaml.composer.Composer.getSingleNode(Composer.java:105)
at org.yaml.snakeyaml.constructor.BaseConstructor.getSingleData(BaseConstructor.java:121)
at org.yaml.snakeyaml.Yaml.loadFromReader(Yaml.java:480)
at org.yaml.snakeyaml.Yaml.load(Yaml.java:399)
Error in ReadYamlRaw (line 42)
result = load_yaml(filename, nosuchfileaction, treatasdata);
Error in ReadYaml (line 48)
ry = ReadYamlRaw(filename, 0, nosuchfileaction, treatasdata);
Error in untitled (line 2)
YamlStruct = ReadYaml(yaml_file);

In MATLAB, select Preferences from the menu/toolstrip. Find the section MATLAB>General>Java Heap Memory, and increase the Java heap size.
You'll need to restart MATLAB after changing this setting for it to take effect.

Related

I'm trying to train the code of Target-Aware Deep Tracking in matlab

I'm for now compiling in CPU version.I am working on matlab 2020a.I've tried to remove the vl_nnconv.m from matconvnet but i still get the following error.
Also the matconvnet i'm using is version matconvnet-1.0-beta25 I'm stuck here since 2 days ,could somebody lease help me out with this issue?
https://github.com/XinLi-zn/TADT
The above is the github code i'm trying to work on.
Foloowing are the errors i'm getting:
Error using vl_nnconv
The option name is not a string (argument number 5)
Error in dagnn.Conv/forward (line 11)
outputs{1} = vl_nnconv(...
Error in dagnn.Layer/forwardAdvanced (line 85)
outputs = obj.forward(inputs, {net.params(par).value}) ;
Error in dagnn.DagNN/eval (line 91)
obj.layers(l).block.forwardAdvanced(obj.layers(l)) ;
Error in get_subwindow_feature (line 37)
net_feat.eval({'input',gpuArray(patch_sw)});
Error in tadt_tracking (line 63)
feat_groups = get_subwindow_feature(net_feat, img, sw_location, input_sz, feat_layer);
Error in Demo_TADT (line 23)
[result, fps]=tadt_tracking(seq_info.img_list, seq_info.gt(1,:), vgg16_model_path, display);
the following are the functions that is causing the error and the argument is obj.pad
function outputs = forward(obj, inputs, params)
if ~obj.hasBias, params{2} = [] ; end
outputs{1} = vl_nnconv(...
inputs{1}, params{1}, params{2}, ...
'pad', obj.pad, ...
'stride', obj.stride, ...
obj.opts{:}) ;
end

Illegal Character Escape in Text.Smolder.Renderer.String.purs

In an attempt to compile my program, I received the following error regarding the file String.purs from the Text.Smolder.Renderer module:
Error found:
at bower_components\purescript-smolder\src\Text\Smolder\Renderer\String.purs:76:
56 - 76:57 (line 76, column 56 - line 76, column 57)
Unable to parse module:
Illegal character escape code
I looked at the source file and found the following at line 76:
toStream s = foldr (\c t -> c :< (Just t)) (mkCofree '\0' Nothing) cs
How can this be corrected? (And how on earth could a compiler error be in a public library!!!)

Error using getImageFromFile (line 11)

My code execute correctly for the digits but it given some errors to the characters. the image presented in that location but it shows image not found like..
Error using getImageFromFile (line 11)
Cannot find the specified file: "C:\Program Files\MATLAB\R2014a\toolbox\vision\visiondemos\characters\handwritten\B\img012-00012".
Error in imageDisplayParseInputs (line 73)
[common_args.CData,common_args.Map] = ...
Error in imshow (line 219)
[common_args,specific_args] = ...
Error in charmodified (line 22)
subplot(2,3,4); imshow(testChar{1,2});

Reading a ply file in matlab (output from Noah Snavely's tool Bundler)

I'm trying to open .ply files and display them in matlab using the following code :
http://people.sc.fsu.edu/~jburkardt/m_src/ply_display/ply_display.m
But it is showing an error
XY_DISPLAY:
Enter the name of the point file (in 'quotes'!).
'C:\SFM\examples\ET\bundle\points001.ply';
27 verbose = 0;
Error using ply_display>ply_to_tri_surface (line 140)
No such file or directory
Error in ply_display (line 48)
[ node_xyz, element_node ] = ply_to_tri_surface ( ply_filename );
Error in ply_display>ply_to_tri_surface (line 732)
ply_display ( 'C:\SFM\examples\new one\bundle\points001.ply' );
Error in ply_display (line 48)
[ node_xyz, element_node ] = ply_to_tri_surface ( ply_filename );
Can anyone please help me regarding this ?
Thanks!
As should be pretty clear from the error output, your error is not in line 27 (actually I don't know why that shows up). What the error trace shows you is this:
1) The error starts when ply_display calls another function, ply_to_tri_surface (which is defined in the same file).
[ node_xyz, element_node ] = ply_to_tri_surface ( ply_filename );
2) Within that second function, the actual error is being triggered at line 140:
Error using ply_display>ply_to_tri_surface (line 140)
No such file or directory
(The reference to line 732 is a bit of a red herring - that is because this is where the error is being returned from ply_to_tri_surface to ply_display I think).
Looking at the actual code, this is the part causing the error (around line 140) - where the program first tries to open your file:
[ fid, Msg ] = fopen ( ply_filename, 'rt' );
if ( fid == -1 )
error ( Msg );
end
That is, ply_filename - your ply file - cannot be found. Either the filename is wrong or the way you are inputting it (are you typing that semicolon at the end of the filename?) is causing issues.
Two options:
1) Run dbstop if error, then re-run the code. When it errors, you should be able to see what ply_filename contains. (Run dbquit to exit debug mode).
2) Input your filename directly when running by calling the function from the command line, e.g. ply_display('test.ply') or ply_display(filename) where filename is a previously defined variable.

read .yml files in matlab

I would like to read .yml files in Matlab. These files contain coordinates x and y of key points on a face image. I looked for different tools but I don't seem to find any answers.
My .yml files look like this
YAML:1.0
Image file: "00032009.jpg"
Contours count: 8
Contours:
-
Name: FO
Count: 41
Closed: 0
Points:
-
x: 682.5947265625000000
y: 743.1998901367187500
-
x: 685.9638061523437500
y: 771.3800659179687500
......
and so on
Note 00032009.jpg is an image of a face
x and y are coordinates of a point on a face Eg: the right corner of an eye etc
Could you please point out a way to read the file and then display the points on the face image?
Edit 1: Here is the error I get
Error: File: ReadYamlRaw.m Line: 14 Column: 11
Expression or statement is incorrect--possibly unbalanced (, {, or [.
Error in ==> ReadYaml at 38
ry = ReadYamlRaw(filename, 0, nosuchfileaction);
What is weird is line 14 in ReadYamlRaw.m
[pth,~,~]= fileparts(mfilename('fullpath'));
Parse error at ','(second one) and ']' usage appears to be invalid matlab syntax.
So what is the use of ~ in there and why is there an error?
Edit2: I replaced the ~ in the line above with dummy variables then I get this errors O_O
Error using ==> ReadYamlRaw>scan at 81
Unknown data type: logical
Error in ==> ReadYamlRaw>scan_map at 138
result.(ich) = scan(r.get(java.lang.String(ich)));
Error in ==> ReadYamlRaw>scan at 79
result = scan_map(r);
Error in ==> ReadYamlRaw>scan_list at 116
result{ii} = scan(i);
Error in ==> ReadYamlRaw>scan at 77
result = scan_list(r);
Error in ==> ReadYamlRaw>scan_map at 138
result.(ich) = scan(r.get(java.lang.String(ich)));
Error in ==> ReadYamlRaw>scan at 79
result = scan_map(r);
Error in ==> ReadYamlRaw>load_yaml at 48
result = scan(yaml.load(fileread([filename, fileext])));
Error in ==> ReadYamlRaw at 19
result = load_yaml(filename, nosuchfileaction);
Error in ==> ReadYaml at 38
ry = ReadYamlRaw(filename, 0, nosuchfileaction);
I also tried with a different yml file that looks like this
%YAML:1.0
RE-C:
x: 919
y: 580
LE-C:
x: 1209
y: 597
N-C:
x: 1063
y: 698
FO-B:
x: 1045
y: 1114
REL-O:
x: 852
y: 597
REL-I:
x: 986
y: 600
REL-T:
x: 918
y: 564
And I get the following errors
Java exception occurred:
while scanning a directive
in "<string>", line 1, column 1:
%YAML:1.0
^
expected alphabetic or numeric character, but found :(58)
in "<string>", line 1, column 6:
%YAML:1.0
^
at org.yaml.snakeyaml.scanner.ScannerImpl.scanDirectiveName(ScannerImpl.java:1028)
at org.yaml.snakeyaml.scanner.ScannerImpl.scanDirective(ScannerImpl.java:990)
at org.yaml.snakeyaml.scanner.ScannerImpl.fetchDirective(ScannerImpl.java:534)
at org.yaml.snakeyaml.scanner.ScannerImpl.fetchMoreTokens(ScannerImpl.java:251)
at org.yaml.snakeyaml.scanner.ScannerImpl.checkToken(ScannerImpl.java:179)
at
org.yaml.snakeyaml.parser.ParserImpl$ParseImplicitDocumentStart.produce(ParserImpl.java:198)
at org.yaml.snakeyaml.parser.ParserImpl.peekEvent(ParserImpl.java:161)
at org.yaml.snakeyaml.parser.ParserImpl.checkEvent(ParserImpl.java:146)
at org.yaml.snakeyaml.composer.Composer.getSingleNode(Composer.java:105)
at org.yaml.snakeyaml.constructor.BaseConstructor.getSingleData(BaseConstructor.java:121)
at org.yaml.snakeyaml.Yaml.loadFromReader(Yaml.java:480)
at org.yaml.snakeyaml.Yaml.load(Yaml.java:399)
Error in ==> ReadYamlRaw>load_yaml at 48
result = scan(yaml.load(fileread([filename, fileext])));
Error in ==> ReadYamlRaw at 19
result = load_yaml(filename, nosuchfileaction);
Error in ==> ReadYaml at 38
ry = ReadYamlRaw(filename, 0, nosuchfileaction);
Maybe someone can make something out of these or you could point out another set of functions that would work? I searched but didn't find any except this one.
It's YAML file indeed (as #DavidBrown mentioned in his comment, the extension does not matter). But it has some problems. Don't know if it's due to wrong YAML format or MATLAB implementation.
I've installed YAMLMATLAB and played a little with your file.
YamlStruct = ReadYaml(yaml_file);
YAMLMATLAB returns error if the files is feed as is. It works only if I comment the first line and remove spaces from field names. So the beginning of the file looks like this:
#YAML:1.0
Imagefile: 00032009.jpg
Contourscount: 8
...skipped the rest...
Then I get the correct structure. For example you can access the 1st point's x coordinate as
YamlStruct.Contours{1}.Points{1}.x
ans =
682.5947
UPDATE
Space in filed names is actually a known problem in YAMLMATLAB. See the report and possible solution here.
UPDATE 2
According to comment from #Jirka_cigler (YAMLMATLAB developers group):
In the program release 0.4.3 we added support for whitespaces in field
names, so the problem should not appear again.
Great!
I've also removed previous developers comment on the problem in the first UPDATE since it's not true any more.
ZozaniDB Database Toolbox comes with a Matlab-native YAML implementation that handles the .yml file here. To parse a string or a file, use:
>> yaml_parse ( str )
>> yaml_read ( filename )