Why is not in my NDK algoritmh.h???? how can i make my std::Sort???? of 1d array
/----------------------------------------------------------
Solved the 2nd question::
and 2. question:my other code started says this error:) SOlved!
Multiple markers at this line
- call of overloaded 'log(int)' is
ambiguous
- candidates are:
in this code:
int m = (int) (log (524288) / log (2));
OK this is solved
std::log has overloads that accept float, double or long double as parameters. The compiler doesn't know which function you are asking for.
Try:
int m = (int) (log (524288.) / log (2.));
Notice that the parameters to log() are now double, not int.
Related
I am following this blog post and GitHub almost exactly:
Blog
Github
But when I run, take a picture and call this line:
var outputs = new float[tfLabels.Count];
tfInterface.Feed("Placeholder", floatValues, 1, 227, 227, 3);
tfInterface.Run(new[] { "loss" });
tfInterface.Fetch("loss", outputs);
The app actually crashes and generates the error below on the .Run line.
I get this error in the output window (and the app crashes):
04-04 17:39:12.575 E/TensorFlowInferenceInterface( 8017): Failed to
run TensorFlow inference with inputs:[Placeholder], outputs:[loss]
Unhandled Exception:
Java.Lang.IllegalArgumentException: Input to reshape is a tensor with
97556 values, but the requested shape requires a multiple of 90944
[[Node: block0_0_reshape0 = Reshape[T=DT_FLOAT, Tshape=DT_INT32,
_device="/job:localhost/replica:0/task:0/device:CPU:0"](block0_0_concat,
block0_0_reshape0/shape)]]
According to the posts I am reading from the searching I am doing on this error, I sort of understand this is due to the image not fitting the expected size exactly but in the example I am following, this is resized to fit 227x227 everytime and converted to float like in these lines:
var resizedBitmap = Bitmap.CreateScaledBitmap(bitmap, 227, 227, false).Copy(Bitmap.Config.Argb8888, false);
var floatValues = new float[227 * 227 * 3];
var intValues = new int[227 * 227];
resizedBitmap.GetPixels(intValues, 0, 227, 0, 0, 227, 227);
for(int i = 0; i < intValues.Length; i++)
{
var val = intValues[i];
floatValues[i * 3 + 0] = ((val & 0xFF) - 104);
floatValues[i * 3 + 1] = (((val >> 8) & 0xFF) - 117);
floatValues[i * 3 + 2] = (((val >> 16) & 0xFF) - 123);
}
So, I don't understand what is causing this or how to fix it. Please help!
UPDATE: I found out the issue is with my model or my labels. I found this out by simply swapping in the model and label file from the sample/github above while leaving all my code the same. When I did this, I no longer get the error. HOWEVER, this still doesn't tell me much. The error is not very explanatory to point me in a direction of what could be wrong with my model. I assume it is the model because the labels file is simply just a text file with labels on each line. I used Custom Vision Service on Azure to create my model. It trained fine and tests just fine on the web portal. I then exported it as TensorFlow. So, I am not sure what I could have done wrong or how to fix it.
Thanks!
After no answers here and several days of searching and trial and error, I have found the issue. In general, I guess this reshape error I was getting you can get if you are feeding the model with an image size other that it is expecting or setup to receive.
The issue is that, everything I have read says that typically you must feed the model with a 227 x 227 x 3 image. Then, I started noticing that size varies on some posts. Some people say 225 x 225 x 3, others say 250 x 250 x 3 and so on. I had tried those sizes as well with no luck.
As you can see in my edit in the question, I did have a clue. When using somebody else's pretrained model, my code works fine. However, when I use my custom model which I created on the Microsoft Azure CustomVision.ai site, I was getting this error.
So, I decided I would try to inspect the models to see what was different. I followed this post: Inspect a pre trained model
When I inspected the model that works using TensorBoard, I see that the input is 227 x 227 x 3 which is what I expected. However, when I viewed my model, I noticed that it was 224 x 224 x 3! I changed my code to resize the image to that size and it works! Problem went away.
So, to summarize, for some reason Microsoft Custom Vision service model generated a model to expect an image size of 224 x 224 x 3. I didn't see any documentation or setting for this. I also don't know if that number will change with each model. If you get a similar shape error, the first place I would check is the size of the image you are feeding your model and what it expects as an input. The good news is you can check your model, even if pre-trained, using TensorBoard and the post I linked above. Look at the input section, it should look something like this:
Hope this helps!
I wish to round up a number in android application with coding as shown below.
float num1= Float.parseFloat(n1.getText().toString());
float num2= Float.parseFloat(n2.getText().toString());
float outc = num1/input;
int final1;
The application getting user input for num1 and num2, and perform to find outc. I wish to rounding up the outc to become an integer final1 where like below:
if outc = 3.8 , final1= 4
if outc = 8.01 , final1= 9
if outc = 12.21 , final1= 13
if outc = 20.45 , final1= 21
*only involve positive value
I try to search for solution, and found that mostly they are normal rounding up solution like this.
It that anyway to perform round up as I mentioned?
Thank you.
Math.ceil()
int result = (int) Math.ceil(outc);
BTW, you can't name variable final, it is reserved word.
Use the ceil function described in:
https://developer.android.com/reference/java/lang/Math.html#ceil(double)
I have an app which uses the Tween method for a number of animations. One of the tweens is the following:
pipe_Tweener.Tween(3.2f,
FLOAT, &pSprite->m_X, (float) -pSprite->GetImage()->GetWidth(),
FLOAT, &pSprite->m_Y, (float) pSprite->m_Y,
FLOAT, &pSprite->m_X, (float) -pSprite->GetImage()->GetWidth(),
FLOAT, &pSprite->m_Y, (float) pSprite->m_Y,
ONCOMPLETE, &Game::ResetP,
END);
and another is:
pipe_Tweener.Tween(JUMP_TIME,
FLOAT, &bSprite->m_X, (float) bSprite->m_X,
FLOAT, &bSprite->m_Y, (float) bSprite->m_Y-JUMP_HEIGHT,
EASING, Ease::sineOut,
ONCOMPLETE, &Game::EndAnimating,
END);
These tweens seem to work fine when debugging using the x86 debug. However when I use the GCC ARM debug I end up with an IwAssert failure at line 360 in IwTween.cpp.
I've debugged through the Tween method, and what I've noticed is that for my first tween everything is fine, I can see the method going through each Type (FLOAT, FLOAT, FLOAT, FLOAT , ONCOMPLETE, END). However for the second tween when the Tween method gets to the END enum, Type becomes 0, (so I see for Type (FLOAT, FLOAT, EASING, ONCOMPLETE, 0) causing the default case statement to execute, which calls the assert failure.
I'm not sure if I'm doing something wrong or if this is a bug with Marmalade itself?
I've actually solved this, but I'll post in case it'll help anyone else.
My EndAnimating method was not static, which was causing some problem in the Tween method. Strangely it only caused a problem when debugging with the ARM simulator.
Hi I am working on an android calculator apps and the now working on the manipuations. I have defined for the following:
ArrayList<Float> inputnum = new ArrayList<Float>();
float inputnum1;
float inputnum2;
and then for the operations,
case MULTIPLY:
inputnum1 = inputnum.get(0);
inputnum2 = inputnum.get(1);
inputnum.add(inputnum1 * inputnum2);
Display.setText(String.format("%.9f", inputnum.get(0)));
similar for the division one.
The muliply function and divide function works well for integers (eg 5* 4 output 20.00000000)
however, when it deals with figures with decimal places, eg 5.3 * 4, it output as 21.12000089, which is incorrect.
what is the problem?
also, how to set output to Display to remove unnecessary zero? eg
when 5*4 it only show 20 instead of 20.000000 as final answer?
when 5.3*4 = 21.12 instead of 21.12000000 as final answer?
Thanks a lot!
Just to change all the related float to double will then avoid presenting the rounding error.
If wanted to present 9 decimal places by filling up zero after the dot, eg 7.56 become 7.560000000, can use the below coding.
Display.setText(String.format("%.9f", inputnum.get(0)));
I have a location with latitude and longitude and want to get a new location that has a distance of x meters from that location at an angle of d degrees. This would be the reverse of Location.distanceBetween(). Is there any Android API to do that. I know that I could program such a function myself, but I wonder if there is an API for it already.
There are some formulae and sample code (JavaScript) for this here: Movable Type Scripts. Look for 'Destination point given distance and bearing from start point'.
Here's an excerpt of the JavaScript from the site:
var lat2 = Math.asin( Math.sin(lat1)*Math.cos(d/R) +
Math.cos(lat1)*Math.sin(d/R)*Math.cos(brng) );
var lon2 = lon1 + Math.atan2(Math.sin(brng)*Math.sin(d/R)*Math.cos(lat1),
Math.cos(d/R)-Math.sin(lat1)*Math.sin(lat2));
In the above code, d is the distance, brng is the bearing in degrees, and R is the Earth's radius.
Porting this to Java should be trivial.
This is called the "first geodesic" (or sometimes "principal geodesic") problem, which will probably help you in finding an algorithm on Google if you need to implement this yourself.
Implement this yourself for now, but do expect this function to show up at some point, so code accordingly - create your own function, add a few unit tests.
In the future add the following to you function:
def myFunc(args):
res = # compute stuff
#if(debug):
res2 = # make api call
assert(res = res2)
return res
And some time later:
def myFunc(args):
return # make api call
And some time later remove the function altogether.
Here is the reverse of it:
SphericalUtil.computeOffsetOrigin(loc1, dist, angle);
It also has the distanceBetween function:
SphericalUtil.computeDistanceBetween(...);
Lib:
SphericalUtil