Likelihood of being admitted to a top 10 CS PhD program? Summary

I'm currently an undergraduate student at a university in the UK that's ranked in the top 10 universities worldwide by both Times Higher Education and QS. I'm in my final year of a 4-year undergraduate program that culminates with a Masters degree in CS.

A brief summary of my academic experience is as follows:


I have a 3.51 GPA (according to the UK-US conversion from https://www.scholaro.com/gpa-calculator) that is the culmination of both coursework and about 24 exams thus far.
In my top 3 exams, I achieved grades over 80% (considered impressive, as 70% is the minimum needed to get a first-class grade) although in 3 exams, I've also achieved grades in the 40-49% region. Although, bear in mind that these exams where I performed extremely poorly, two occurred in my first year and one in my second year. 
At the end of my second year, I spent time over the summer working as an undergraduate research assistant in the CS dept. on a project that did not go badly, but also did not result in any published academic papers.
I'm currently starting out my Masters thesis on an exciting project that has the potential to result in a publication depending on how good my work is.


At my university, exams are what make up the bulk of your final grade - followed by your Masters thesis and then your overall coursework average over the 4 years. My exams thus far are actually quite unimpressive, as most people in my cohort are obtaining firsts and the very best are obtaining averages close to (and some even above) 80%. For reference, my average is just over 64%.

Factors that are leading me to seriously question whether I should do a PhD, despite my interest in research:


The aim of undergraduate courses is to imbue students with a basic understanding of fundamental topics, and I have demonstrated quite mediocre performance in a sizeable portion of these courses.
I come from a demographic that is severely underrepresented in STEM and generates a very, very low quantity of total scientific knowledge in STEM. I can count on one hand the number of computer scientists I know about who (1) work in the sub-field of CS that I'm interested in (machine learning), and (2) come from a similar demographic to me. I do not think that I am "special" and given this empirical evidence, it appears to me that people with a background similar to mine may not have the right skill-set to be successful scientists. Note that I cannot explain why this is the case, I'm simply taking a "outside view" of the situation and making inferences based on what I observe (Daniel Kahneman explains the utility of the method here: Daniel Kahneman: Beware the Inside View).
My position, based on my academic performance and research experience thus far, is that I do not currently stand a chance of being a successful scientist in the near future. If I am not a successful scientist, it is unlikely that I will obtain a promising research-oriented job in a country with high scientific output in STEM (e.g. US, UK, Canada, etc.). Consequently, I would likely have to return to my home country - a developing country - where, due to the lack of resources and poor levels of education, I would be unable conduct high-impact STEM research and so my PhD would simply go to waste.


Note that my aim is not simply to "get a PhD", but rather to obtain a high confidence estimate of the likelihood that I would be a successful scientist.
I'm currently in a Computer Science PhD program in Canada, and from my point of view you have a few misconceptions.


Getting into a top school is not necessary to be a successful researcher. Your advisor will have far greater impact on your research output than the choice of school. "Top" schools often have famous professors, who will take on many graduate students and have little time for them individually.
Your demographic does not matter, and it may in fact strengthen your application, if schools have equity programs.
If you manage to get into a grad school, your performance in undergrad isn't necessarily a good indicator of your research abilities. Memorization and exams are  big in undergrad, but hold little weight in grad school. Writing ability, communication skills, and the ability to perform self directed research are far more important.


I would find a school that has a few professors you'd be interested in working with and apply. The worst that happens is you don't get in.