Hi~ I'm now using the implementation from https://github.com/KaiyangZhou/pytorch-center-loss, and the center was initilized as self.centers = nn.Parameter(torch.randn(self.num_classes, self.feat_dim)). I'm confused why this kind of initialization guarantee the final center is the center of the given features/embeddings in a certain class?
I tried this center loss as above but confused why it works in theory?
Related
I am writing an application using ArCore. I am getting an object's pose as a Hitresult, therefore the object is placed correctly in the plane, but not correctly orientated/rotated towards the smartphone. For a more complete problem description:
The object is a 2d rectangle and is intended to stay inside the plane (= same normal vectors). The rectangle also needs to "point" to the camera (= nearest border needs to be aligned with the smartphone screen).
currentObstaclePose = hit.getHitPose().extractTranslation().compose(frame.getCamera().getPose().extractRotation())
Using this approach I do not get matching normal vectors for object and plane.
I have no idea how to construct the objects quaternions in a manner to achieve my goal. Thanks in advance for your help.
It sounds like you want to set the 'look direction' of the renderable.
Assuming you are using Scenefrom, which I see is tagged, you can use a TransformableNode and the method setLookDirection.
The example below will set the direction of the renderable, depending on the value you set for lookDirection:
var newAnchorNode:AnchorNode = AnchorNode(newAnchor)
var transNode = TransformableNode(arFragment.transformationSystem)
transNode.setLookDirection(Vector3(0f, xPoint.toFloat(), yPoint.toFloat()), lookDirectionValue)
transNode.renderable = yourRenderable
transNode.setParent(newAnchorNode)
newAnchorNode.setParent(arFragment.arSceneView.scene)
setAnchorNodes.add(newAnchorNode)
My question is pretty simple yet I cannot find an answer anywhere in documentation or on stack.
I am working on a game in Corona SDK and I have created a physics body that will be thrown across the screen. The physics body is an image. The object is meant to be a projectile and I would like to use the natural physics inherent to Corona to govern how the object reacts to being thrown across the screen. In order to do this it would be ideal for the object's center of mass to be at the nose/point of the object, somewhat like a badminton shuttle.
The question is: is there a way to set a custom center of mass of a physics body in Corona?
I have figured out how to do this, so I am posting my solution here so that others may find it.
Corona does not have a method or property that can be used to change the center of mass for a particular object.
The best way to change the center of mass of an object is to create another object with a heavier density than the original, position Object B at the x,y of the desired position for the center of mass, then make object B's density greater than Object A. Then using a weld joint, join the two objects and thereafter apply any linear forces to the center of mass of Object B. Object B will then drag Object A along as it is rigidly attached via the weld joint.
I have been trying to find, but did not succeed. Is there a way to change physicsworld gravity property in such way, that objects would not be attracted towards the bottom of the screen, but to the centre of it instead?
Use an SKFieldNode for that. Just place it at the center of your map and disable gravity by putting code in that sets the gravity to zero (CGVector(0,0))
I would give you code, but I don't use Objective C, so I don't know the exact syntax for it. I can give it a shot though... [physicsBody setGravity: CGVector(0,0)]; PLEASE NOTE I HAVE NO IDEA IF THAT IS CORRECT SYNTAX
EDIT:
The asker requested an example of SKFieldNode in Swift, so here it goes.
For the question asked, what you would do is create a Radial Gravity Field node at the center. This code goes in GameScene.swift (or .m if you're using Objective C, and make sure you change the syntax to Obj-C).
let gravField = SKFieldNode.radialGravityField(); // Create grav field
gravField.position.x = size.width/2; // Center on X axis
gravField.position.y = size.height/2; // Center on Y axis (Now at center of screen)
addChild(gravField); // Add to world
You are probably looking for a SKFieldNode. There are a couple of different types so you will have to read the docs. The one you are probably looking for is called radialGravityField.
I am working on a small education demo which should measure height and width of the object using iOS camera.
EDIT:
I have a new theory to measure the width of an object.
In above image, if i can get Angle α and Angle ß, i can get width of the unknown side by using trigonometry formulas. I have the values of b1 and b2 already.
OLD:
Right now, i am focusing on measuring length only.
As per my knowledge it should be 3 step process.
User snaps one end of the object.
User snaps other end of the object.
User snaps center of the object. (Suggest me a better way for these please)
I get the approximate measurements using above process, but for the 3rd step, in which user snaps the center of the object. I want to show pointer location on screen (as camera overlay) to help user determine the center of the object.
This is how i am doing it right now.
How can i draw pointer location for 3rd step?
Note: Please suggest alternative/best way to make it possible. I would love another suggestions. Thanks.!!
First of all I must appreciate your work you have done till now. Another good thing is the way of explaining, salute!!!!!
After reading of your question, I feel that you dont need code, you can do it. I think you need direction only.
As per your explanation, you want to record angle of rotation of the device.
If you want to measure angle of rotation, you have to use compas readings. But compas readings will change if user tild the device. So you have to use accelerometer to measure tilding of device.
In short you have to make some combination and equation of both compas and accelerometer readings. Use compas to measure angle and use accelerometer to measure tilding of device.
If you want further information to implement it, you can ask me.
Hope this will help you....
I am working on a iOS Game Application (Race) which requires the background to have transition coming forward.
For the above requirement I have written a code where I have to make people feel as if the objects were coming from a far distance to nearby.
Hence I am using transition to do so where I increase their y position and scaling (both xScale and yScale). While doing so, the problem I am facing is when the objects seem to come closer with their size increasing (using scaling), the distance between the objects decreases from their actual distance because of scaling and it does not perfectly look as if the objects were coming from far behind.
Please let me know what is the best way to achieve what I trying to do or else if there is any available sample code having the functionality of car/bike racing.
transition.to ( object,{ time=500, alpha=1,x = (destination x coor),y = (destination y coor),width =(to scale x),height =( to scale y), onComplete=saltCellarOnComplete} )