Map Inference in the Face of Noise and Disparity代码重现遇到的问题(持续更新....)

1. 论文链接

Map Inference in the Face of Noise and Disparity
代码下载地址

2. 安装环境

python 2.7.15 win64位
Opencv 2.4.13 win64位 (安装过程可参考windows平台下python安装opencv,即实现import cv2功能
pycharm 2019.3.3 win64位(来源微信公众号PyCharm2019【中文版】安装教程

3. 遇到的问题和解决方法

3.1 第一步运行kde.py

#coding:utf-8
import cv2
import cv2.cv as cv
from math import atan2, sqrt, ceil, pi, fmod
import sys, getopt, os
from location import TripLoader
from pylibs import spatialfunclib
from itertools import tee, izip
import sqlite3

##
## important parameters
##

cell_size = 1 # meters
gaussian_blur = 17
trips_path = "trips/trips_1m/"

def pairwise(iterable):
    "s -> (s0,s1), (s1,s2), (s2, s3), ..."
    a, b = tee(iterable)
    next(b, None)
    return izip(a, b)

class KDE:
    def __init__(self):
        pass
    
    def create_kde_with_trips(self, all_trips):
        
        print "trips path: " + str(trips_path)
        print "cell size: " + str(cell_size)
        print "gaussian blur: " + str(gaussian_blur)
        
        # flag to save images
        save_images = True
        
        sys.stdout.write("\nFinding bounding box... ")
        sys.stdout.flush()
        
        min_lat = all_trips[0].locations[0].latitude
        max_lat = all_trips[0].locations[0].latitude
        min_lon = all_trips[0].locations[0].longitude
        max_lon = all_trips[0].locations[0].longitude
        
        for trip in all_trips:
            for location in trip.locations:
                if (location.latitude < min_lat):
                    min_lat = location.latitude
                
                if (location.latitude > max_lat):
                    max_lat = location.latitude
                
                if (location.longitude < min_lon):
                    min_lon = location.longitude
                
                if (location.longitude > max_lon):
                    max_lon = location.longitude
        
        print "done."
        
        # find bounding box for data
        min_lat -= 0.003
        max_lat += 0.003
        min_lon -= 0.005
        max_lon += 0.005
        
        diff_lat = max_lat - min_lat
        diff_lon = max_lon - min_lon
        
        #print min_lat, min_lon, max_lat, max_lon
        
        width = int(diff_lon * spatialfunclib.METERS_PER_DEGREE_LONGITUDE / cell_size)
        height = int(diff_lat * spatialfunclib.METERS_PER_DEGREE_LATITUDE / cell_size)
        yscale = height / diff_lat # pixels per lat
        xscale = width / diff_lon # pixels per lon
        
        # aggregate intensity map for all traces
        themap = cv.CreateMat(height,width,cv.CV_16UC1)
        cv.SetZero(themap)
        
        ##
        ## Build an aggregate intensity map from all the edges
        ##
        
        trip_counter = 1
        
        for trip in all_trips:
            
            if ((trip_counter % 10 == 0) or (trip_counter == len(all_trips))):
                sys.stdout.write("\rCreating histogram (trip " + str(trip_counter) + "/" + str(len(all_trips)) + ")... ")
                sys.stdout.flush()
            trip_counter += 1
            
            temp = cv.CreateMat(height,width,cv.CV_8UC1)
            cv.SetZero(temp)
            temp16 = cv.CreateMat(height,width,cv.CV_16UC1)
            cv.SetZero(temp16)
            
            for (orig,dest) in pairwise(trip.locations):
                oy = height - int(yscale * (orig.latitude - min_lat))
                ox = int(xscale * (orig.longitude - min_lon))
                dy = height - int(yscale * (dest.latitude - min_lat))
                dx = int(xscale * (dest.longitude - min_lon))
                cv.Line(temp, (ox, oy), (dx, dy), (32), 1, cv.CV_AA)
            
            # accumulate trips into themap
            cv.ConvertScale(temp,temp16,1,0)
            cv.Add(themap,temp16,themap)
        
        lines = cv.CreateMat(height,width,cv.CV_8U)
        cv.SetZero(lines)
        
        print "done."
        
        trip_counter = 1
        
        for trip in all_trips
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
以下是使用 PyTorch 进行 MLPerf Inference ResNet50 测试的代码示例,包括生成 `val_map.txt` 文件的步骤: ```python import os import random import torch import torchvision.transforms as transforms from PIL import Image # Set random seed for reproducibility random.seed(1) # Define ImageNet dataset root directory and validation set directory data_root = '/path/to/imagenet' val_dir = 'val/my_val_set' # Define the path to the validation set images and val_map.txt file val_dir_path = os.path.join(data_root, val_dir) val_map_file = os.path.join(data_root, 'val_map.txt') # If the val_map.txt file does not exist, create it if not os.path.exists(val_map_file): # Get a list of the validation set image filenames val_images = os.listdir(val_dir_path) val_images = [x for x in val_images if x.endswith('.JPEG')] # Shuffle the list of validation set image filenames random.shuffle(val_images) # Write the val_map.txt file with open(val_map_file, 'w') as f: for i, val_image in enumerate(val_images): f.write('{} {}\n'.format(i, os.path.join(val_dir, val_image))) # Define the transforms to be applied to the validation set images val_transforms = transforms.Compose([ transforms.Resize(256), transforms.CenterCrop(224), transforms.ToTensor(), transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225]) ]) # Load the validation set images and labels val_dataset = torchvision.datasets.ImageFolder(val_dir_path, transform=val_transforms) val_loader = torch.utils.data.DataLoader(val_dataset, batch_size=1, shuffle=False) # Load the ResNet50 model and set it to evaluation mode model = torchvision.models.resnet50(pretrained=True) model.eval() # Initialize variables for tracking top-1 and top-5 accuracy top1_correct = 0 top5_correct = 0 total = 0 # Loop over the validation set and compute the model's top-1 and top-5 accuracy with torch.no_grad(): for i, (input, target) in enumerate(val_loader): # Forward pass through the model output = model(input) # Compute the top-1 and top-5 predictions _, top1_pred = output.topk(1, 1, True, True) _, top5_pred = output.topk(5, 1, True, True) # Update the top-1 and top-5 accuracy counters top1_correct += (top1_pred == target).sum().item() top5_correct += (top5_pred == target.view(-1, 1)).sum().item() total += 1 # Compute and print the top-1 and top-5 accuracy top1_acc = top1_correct / total top5_acc = top5_correct / total print('Top-1 accuracy: {:.2%}'.format(top1_acc)) print('Top-5 accuracy: {:.2%}'.format(top5_acc)) ``` 在上面的代码中,我们首先检查是否存在 `val_map.txt` 文件。如果不存在,我们会扫描文件夹中的所有图像文件,打乱它们的顺序,并将它们的文件名和索引写入 `val_map.txt` 文件中。然后,我们定义了用于对图像进行预处理和加载的 PyTorch transforms,并使用它们来实例化 `ImageFolder` 类,该类允许我们轻松地加载整个图像集并将其转换为 PyTorch `Dataset` 对象。最后,我们迭代整个验证集,对每个图像执行前向传递,并计算模型的 top-1 和 top-5 准确度。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值