动态天空置换算法SkyAR体验

动态天空置换算法SkyAR体验

之前在手机拍照过程中体验过一些有趣的AR特效,而近日偶然发现这个动态天空置换算法SkyAR,遂将实现过程记录如下。

github网址:https://github.com/jiupinjia/SkyAR

论文网址:Castle in the Sky: Dynamic Sky Replacement and Harmonization in Videos

效果演示


代码运行

1. 下载代码

git clone https://github.com/jiupinjia/SkyAR.git

2. 搭建虚拟环境

conda create -n SkyAR python=3.9

conda activate SkyAR

3. 安装依赖

conda install pytorch torchvision torchaudio pytorch-cuda=11.6 -c pytorch -c nvidia

Requirement.txt

matplotlib
scikit-image
scikit-learn
scipy
numpy
torch
torchvision
opencv-python
opencv-contrib-python
4. 下载权重文件

链接:https://pan.baidu.com/s/1gCzZX6Qpxv3PLtcYetuCaw
提取码:gou6

将权重文件放至SkyAr目录下

5. 代码测试

在虚拟环境下运行

python skymagic.py --path ./config/config-canyon-galaxy.json

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
最佳置换算法是一种页面置换算法,其思想是查找内存中将来最长时间不使用的页面,然后将当前页面替换成该页面。以下是最佳置换算法的编程实现。 首先,我们需要定义一个列表来存储当前内存中的页面和它们的访问时间。每当页面被访问时,我们需要更新它的访问时间。 ``` # 定义列表来存储页面和它们的访问时间 memory = [] # 初始化内存 def initialize_memory(size): global memory memory = [[None, float("inf")] for _ in range(size)] # 更新页面的访问时间 def update_access_time(page): global memory for i in range(len(memory)): if memory[i][0] == page: memory[i][1] = float("inf") else: memory[i][1] -= 1 # 查找最长时间不使用的页面 def find_replace_page(): global memory replace_page = None for page, access_time in memory: if access_time < float("inf"): if replace_page is None or access_time > memory[replace_page][1]: replace_page = memory.index([page, access_time]) return replace_page ``` 然后,我们需要实现最佳置换算法的主要逻辑。当内存已满且新页面需要插入时,我们需要查找最长时间不使用的页面并将其替换成新页面。 ``` # 最佳置换算法 def best_fit(page): global memory if [page, float("inf")] not in memory: page_index = None for i in range(len(memory)): if memory[i][0] is None: memory[i] = [page, float("inf")] return elif memory[i][0] == page: update_access_time(page) return elif page_index is None or memory[i][1] > memory[page_index][1]: page_index = i memory[page_index] = [page, float("inf")] else: update_access_time(page) # 页面替换 def page_replace(algo, pages, size): global memory initialize_memory(size) page_faults = 0 for page in pages: if page not in [p[0] for p in memory]: page_faults += 1 if None in [p[0] for p in memory]: memory[[p[0] for p in memory].index(None)] = [page, float("inf")] else: replace_page_index = find_replace_page() memory[replace_page_index] = [page, float("inf")] else: update_access_time(page) return page_faults ``` 最后,我们可以调用 `page_replace` 函数来测试最佳置换算法。 ``` pages = [7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2] print("Page faults:", page_replace("best_fit", pages, 4)) ``` 输出结果为: ``` Page faults: 7 ```

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值