Where the giants came from is a mystery. They don't seem to fit at all easily into Tolkien's universe, but there are some possible explanations.
The first of these is the simplest - that they didn't actually exist. As Bilbo and his friends travelled through the Mountains, they encountered a thunderstorm, and Tolkien says, '...across the valley the stone-giants were out, and were hurling rocks at one another for a game...' (The Hobbit 4 'Over Hill and Under Hill'). This could just be a metaphor for the crashing of the thunder and lightning, and if so, it's possible that there were no giants at all. In truth, though, this seems a rather unlikely possibility, and the characters in The Hobbit certainly behave as if the giants are real. Thorin is even worried about being picked up by them, and much later Gandalf suggests finding a friendly giant to deal with the goblins in the Mountains.
If we presume that the giants were real - and they do seem to have been - the next possibility to consider is that they might have belonged in some way to the race of Men. This isn't as far-fetched as it might seem. We do know, for instance, that both Hobbits and Drûgs were distantly related to Men. If a very small type of Man - the Hobbit - could develop, why not an especially large type as well? There is some slight support for this possibility among the drafts of The Lord of the Rings, where we're told that '...giants were spoken of, a Big Folk only far bigger and stronger than Men the [?ordinary] Big Folk...' (The History of Middle-earth volume VI, The Return of the Shadow XV 'Ancient History').
If it's possible that giants were a type of Men, it's at least equally possible that they were actually Ents. After all, in its ultimate origins Ent is just an Anglo-Saxon word for 'giant', and in his original conception, Tolkien referred, for example, to 'the Giant Treebeard'. What's more, in Pippin's description of the destruction of Isengard, we hear that the Ents were '...hurling avalanches of boulders down the shafts, tossing up huge slabs of stone into the air like leaves.' The Two Towers III 9 'Flotsam and Jetsam'). This is more than a little reminiscent of Bilbo's encounter in the Misty Mountains.
It's important to remember that, at the time he was writing The Hobbit, Tolkien was engaged in writing a simple children's story. It's unlikely that he gave much thought to fitting the giants into a larger scheme. Indeed, at that point, the Ents did not even exist in his imagination, so any later explanation - if indeed he devised one at all - must have been fitted to the facts after the event.