-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ergun Acikoz
committed
Jul 9, 2024
1 parent
fda6bb9
commit e791e70
Showing
31 changed files
with
615 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Japan, South Korea, Taiwan, Hong Kong, Thailand, Indonesia, Malaysia, Singapore, Cambodia, Laos, Philippines, Bangladesh, Sri Lanka, Bhutan, Kyrgyzstan, Mongolia, United Arab Emirates, Jordan, Palestine, Qatar, Israel, Tunisia, Senegal, Ghana, Nigeria, Kenya, Uganda, Rwanda, Botswana, Lesotho, Eswatini, South Africa, United Kingdom, France, Spain, Ireland, Germany, Austria, Switzerland, Italy, Iceland, Norway, Denmark, Sweden, Finland, Estonia, Latvia, Lithuania, Hungary, Poland, Czechia, Slovakia, Bulgaria, Romania, Serbia, Albania, Greece, North Macedonia, Croatia, Slovenia, Ukraine, United States, Canada, Mexico, Greenland, Guatemala, Dominican Republic, Puerto Rico, Panama, Brazil, Ecuador, Colombia, Peru, Bolivia, Chile, Argentina, Uruguay, Australia, New Zealand, Belgium, Netherlands, Turkiye, Russian Federation, United States, Vietnam, Kazakhstan, Czech Republic, Costra Rica, Honduras, Nicaragua |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import geopandas as gpd | ||
from shapely.geometry import Polygon | ||
from shapely.ops import unary_union | ||
from geopandas.tools import sjoin | ||
import pandas as pd | ||
import pyproj | ||
import matplotlib.pyplot as plt | ||
from PIL import Image | ||
import requests | ||
import os | ||
from transformers import CLIPProcessor, CLIPModel | ||
|
||
# Reading in the countries from the file | ||
|
||
countries = gpd.read_file("countries.geojson") | ||
|
||
# Getting countries that are on streetview | ||
|
||
with open('countries.txt', 'r') as file: | ||
street_view = file.read().split(', ') | ||
|
||
#keep countries that are in street view in table and get rid of rest | ||
countries_street_view = countries[countries['COUNTRY'].isin(street_view)] | ||
|
||
# Grabbing the clip model to use in our code | ||
model = CLIPModel.from_pretrained("geolocal/StreetCLIP") | ||
processor = CLIPProcessor.from_pretrained("geolocal/StreetCLIP") | ||
|
||
|
||
def inference(labels, image, actual): | ||
inputs = processor(text=labels, images=image, return_tensors="pt", padding=True) | ||
# run the CLIP model | ||
outputs = model(**inputs) | ||
# calculate probabilities | ||
logits_per_image = outputs.logits_per_image | ||
probs = logits_per_image.softmax(dim=1).detach().numpy() | ||
# Identify the country with the highest probability | ||
max_prob_index = probs.argmax() | ||
predicted = street_view[max_prob_index] | ||
return predicted | ||
|
||
|
||
res = open(os.path.join(os.getcwd(),'test/result.txt'), mode="r") | ||
lines = res.readlines() | ||
accuracy = [] | ||
|
||
for i, line in enumerate(lines): | ||
image = Image.open(os.path.join(os.getcwd(), f'test/images/test{i}.jpg')) | ||
predicted = inference(street_view, image, line) | ||
print(f'Predicted: {predicted}\nActual: {line}') | ||
if (predicted == line[:-1]): | ||
accuracy.append(1) | ||
else: | ||
accuracy.append(0) | ||
|
||
|
||
avg_accuracy = sum(accuracy) / len(accuracy) | ||
print(f"Accuracy: {avg_accuracy}") | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import geopandas as gpd | ||
from shapely.geometry import Polygon | ||
from shapely.ops import unary_union | ||
from geopandas.tools import sjoin | ||
import pandas as pd | ||
import pyproj | ||
import matplotlib.pyplot as plt | ||
from PIL import Image | ||
import requests | ||
import os | ||
from transformers import CLIPProcessor, CLIPModel | ||
import numpy as np | ||
|
||
|
||
|
||
# Reading in the countries from the file | ||
|
||
countries = gpd.read_file("countries.geojson") | ||
|
||
# Getting countries that are on streetview | ||
|
||
with open('countries.txt', 'r') as file: | ||
street_view = file.read().split(', ') | ||
|
||
#keep countries that are in street view in table and get rid of rest | ||
countries_street_view = countries[countries['COUNTRY'].isin(street_view)] | ||
|
||
# Grabbing the clip model to use in our code | ||
model = CLIPModel.from_pretrained("geolocal/StreetCLIP") | ||
processor = CLIPProcessor.from_pretrained("geolocal/StreetCLIP") | ||
|
||
|
||
def inference(labels, image): | ||
inputs = processor(text=labels, images=image, return_tensors="pt", padding=True) | ||
# run the CLIP model | ||
outputs = model(**inputs) | ||
# calculate probabilities | ||
logits_per_image = outputs.logits_per_image | ||
probs = logits_per_image.softmax(dim=1).detach().numpy() | ||
# Identify the country with the highest probability | ||
max_prob_index = probs.argmax() | ||
predicted = street_view[max_prob_index] | ||
return predicted | ||
|
||
|
||
all = [] | ||
|
||
for i in np.arange(4): | ||
image = Image.open(os.path.join(os.getcwd(), f'image{i}.jpg')) | ||
predicted = inference(street_view, image) | ||
all.append(predicted) | ||
|
||
def mostFrequent(arr, n): | ||
maxcount = 0; | ||
element_having_max_freq = 0; | ||
for i in range(0, n): | ||
count = 0 | ||
for j in range(0, n): | ||
if(arr[i] == arr[j]): | ||
count += 1 | ||
if(count > maxcount): | ||
maxcount = count | ||
element_having_max_freq = arr[i] | ||
|
||
return element_having_max_freq; | ||
print(all) | ||
print(mostFrequent(all, len(all))) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,208 @@ | ||
const { spawn } = require('child_process') | ||
// const child = spawn('pwd') | ||
|
||
const puppeteer = require("puppeteer"); | ||
|
||
async function runPythonScript(scriptPath, args) { | ||
|
||
// Use child_process.spawn method from | ||
// child_process module and assign it to variable | ||
const pyProg = spawn('python', [scriptPath].concat(args)); | ||
|
||
// Collect data from script and print to console | ||
let data = ''; | ||
pyProg.stdout.on('data', (stdout) => { | ||
data += stdout.toString(); | ||
}); | ||
|
||
// Print errors to console, if any | ||
pyProg.stderr.on('data', (stderr) => { | ||
console.log(`stderr: ${stderr}`); | ||
}); | ||
|
||
// When script is finished, print collected data | ||
pyProg.on('close', (code) => { | ||
console.log(`child process exited with code ${code}`); | ||
console.log(data); | ||
}); | ||
} | ||
|
||
(async () => { | ||
browser = await puppeteer.launch({headless: false, ignoreHTTPSErrors: true, | ||
args: [`--window-size=1920,1080`], | ||
defaultViewport: { | ||
width: 1920, | ||
height: 1080, | ||
}, | ||
}); | ||
page = await browser.newPage(); | ||
await page.goto("https://geoguessr.com/signin"); | ||
try { | ||
await page.waitForSelector('#onetrust-accept-btn-handler', { timeout: 2000 }); | ||
await page.click('#onetrust-accept-btn-handler'); | ||
} catch (error) { | ||
console.log('no cookie popup'); | ||
} | ||
await page.waitForTimeout(500) | ||
|
||
|
||
|
||
const userClick = await page.waitForSelector( | ||
"main.version4_main__DAsSW input[class='text-input_textInput__HPC_k']" | ||
); | ||
|
||
await userClick.click(); | ||
|
||
await page.keyboard.type("YOUR-EMAIL-HERE"); | ||
|
||
await page.waitForTimeout(500) | ||
|
||
|
||
const passClick = await page.waitForSelector( | ||
"main.version4_main__DAsSW input[name='password']" | ||
); | ||
|
||
await passClick.click(); | ||
|
||
await page.keyboard.type("YOUR-PASSWORD-HERE") | ||
await page.waitForTimeout(500) | ||
|
||
|
||
|
||
const loginClick = await page.waitForSelector("main.version4_main__DAsSW span[class='button_label__kpJrA']"); | ||
|
||
await loginClick.click(); | ||
await page.waitForTimeout(500) | ||
|
||
try { | ||
const exit = await page.waitForSelector("div.modal_contentContainer__jOaNm button[class = 'modal_closeButton__rq9h_']", { timeout: 2000 }); | ||
await exit.click(); | ||
} catch (error) { | ||
console.log('nopopup'); | ||
} | ||
|
||
await page.waitForTimeout(500); | ||
|
||
const singlePlayer = await page.waitForSelector("main.version4_main__DAsSW button[class='game-menu-button_button__WPwVi']"); | ||
|
||
await singlePlayer.click(); | ||
|
||
await page.waitForTimeout(500); | ||
|
||
const rightArrow = await page.waitForSelector("main.version4_main__DAsSW button[class='horizontal-scroll-arrows_arrowButton__yOI_1 horizontal-scroll-arrows_right__9X_Cu horizontal-scroll-arrows_rightPadding__7_4xW']") | ||
|
||
await rightArrow.click(); | ||
|
||
await page.waitForTimeout(2000); | ||
|
||
await page.mouse.click(450, 650) | ||
|
||
await page.waitForTimeout(2000); | ||
|
||
await page.mouse.click(700, 500) | ||
|
||
await page.waitForTimeout(2000); | ||
|
||
await page.mouse.click(960, 555) | ||
|
||
await page.waitForTimeout(4000); | ||
await page.mouse.click(960, 540) | ||
await page.waitForTimeout(3000); | ||
await page.screenshot({ path: `image0.jpg` }); | ||
await page.keyboard.down('ArrowRight'); | ||
await page.waitForTimeout(1000); | ||
await page.screenshot({ path: `image1.jpg` }); | ||
await page.waitForTimeout(1000); | ||
await page.screenshot({ path: `image2.jpg` }) | ||
await page.waitForTimeout(1000); | ||
await page.screenshot({ path: `image3.jpg` }) | ||
await page.keyboard.up('ArrowRight'); | ||
|
||
await page.waitForTimeout(1000); | ||
await runPythonScript("model.py", ["hello", "world"]); | ||
|
||
await page.waitForTimeout(30000); | ||
|
||
await page.mouse.click(960, 540) | ||
await page.waitForTimeout(3000); | ||
await page.screenshot({ path: `image0.jpg` }); | ||
await page.keyboard.down('ArrowRight'); | ||
await page.waitForTimeout(1000); | ||
await page.screenshot({ path: `image1.jpg` }); | ||
await page.waitForTimeout(1000); | ||
await page.screenshot({ path: `image2.jpg` }) | ||
await page.waitForTimeout(1000); | ||
await page.screenshot({ path: `image3.jpg` }) | ||
await page.keyboard.up('ArrowRight'); | ||
|
||
|
||
await page.waitForTimeout(1000); | ||
await runPythonScript("model.py", ["hello", "world"]); | ||
|
||
|
||
await page.waitForTimeout(30000); | ||
|
||
|
||
await page.mouse.click(960, 540) | ||
await page.waitForTimeout(3000); | ||
await page.screenshot({ path: `image0.jpg` }); | ||
await page.keyboard.down('ArrowRight'); | ||
await page.waitForTimeout(1000); | ||
await page.screenshot({ path: `image1.jpg` }); | ||
await page.waitForTimeout(1000); | ||
await page.screenshot({ path: `image2.jpg` }) | ||
await page.waitForTimeout(1000); | ||
await page.screenshot({ path: `image3.jpg` }) | ||
await page.keyboard.up('ArrowRight'); | ||
|
||
|
||
await page.waitForTimeout(1000); | ||
await runPythonScript("model.py", ["hello", "world"]); | ||
|
||
await page.waitForTimeout(30000); | ||
|
||
await page.mouse.click(960, 540) | ||
await page.waitForTimeout(3000); | ||
await page.screenshot({ path: `image0.jpg` }); | ||
await page.keyboard.down('ArrowRight'); | ||
await page.waitForTimeout(1000); | ||
await page.screenshot({ path: `image1.jpg` }); | ||
await page.waitForTimeout(1000); | ||
await page.screenshot({ path: `image2.jpg` }) | ||
await page.waitForTimeout(1000); | ||
await page.screenshot({ path: `image3.jpg` }) | ||
await page.keyboard.up('ArrowRight'); | ||
|
||
|
||
await page.waitForTimeout(1000); | ||
await runPythonScript("model.py", ["hello", "world"]); | ||
|
||
await page.waitForTimeout(30000); | ||
|
||
await page.mouse.click(960, 540) | ||
await page.waitForTimeout(3000); | ||
await page.screenshot({ path: `image0.jpg` }); | ||
await page.keyboard.down('ArrowRight'); | ||
await page.waitForTimeout(1000); | ||
await page.screenshot({ path: `image1.jpg` }); | ||
await page.waitForTimeout(1000); | ||
await page.screenshot({ path: `image2.jpg` }) | ||
await page.waitForTimeout(1000); | ||
await page.screenshot({ path: `image3.jpg` }) | ||
await page.keyboard.up('ArrowRight'); | ||
|
||
|
||
await page.waitForTimeout(1000); | ||
await runPythonScript("model.py", ["hello", "world"]); | ||
|
||
|
||
|
||
await page.waitForTimeout(30000); | ||
|
||
await browser.close(); | ||
|
||
|
||
|
||
|
||
|
||
})(); |
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
Chile | ||
Greece | ||
Turkiye | ||
Turkiye | ||
Taiwan | ||
Spain | ||
Norway | ||
Malaysia | ||
Kenya | ||
Botswana | ||
Rwanda | ||
Australia | ||
Argentina | ||
Bolivia | ||
Germany | ||
Indonesia | ||
Singapore | ||
South Africa | ||
South Korea | ||
Romania |