You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Jupyter Notebook中以缩略图查看RunPod服务器输出文件夹图片

在Jupyter Notebook中以缩略图查看并删除Stable Diffusion生成的图片

完全可行,以下是针对新手的分步操作:

1. 打开Jupyter Notebook并进入目标文件夹

  • 登录RunPod控制台,找到你的GPU Pod,点击「Connect」选择Jupyter Notebook入口进入
  • 在左侧文件浏览器里找到outputs文件夹,点击进入该目录

2. 创建新的代码笔记本

  • 点击页面右上角的「New」按钮,选择「Python 3」创建一个空白代码笔记本

3. 运行生成缩略图的代码

  • 在新笔记本的第一个代码单元格中,粘贴以下代码:
import os
from IPython.display import display, Image, Button
from ipywidgets import widgets

# 当前目录就是outputs文件夹,无需修改
img_dir = './'

# 筛选常见图片格式
img_extensions = ['.png', '.jpg', '.jpeg', '.webp']
img_files = [f for f in os.listdir(img_dir) if os.path.splitext(f)[1].lower() in img_extensions]

# 构建图片+删除按钮的展示容器
box = widgets.VBox()
content_rows = []

for img_file in img_files:
    img_path = os.path.join(img_dir, img_file)
    # 生成缩略图,width可调整大小(比如改成300显示更大的图)
    img_display = Image(filename=img_path, width=200)
    # 创建删除按钮
    delete_btn = Button(description=f"删除 {img_file}", button_style='danger')
    
    # 绑定删除功能
    def delete_image(b, file_path=img_path, file_name=img_file):
        os.remove(file_path)
        print(f"已删除:{file_name}")
        # 移除已删除的元素
        box.children = [row for row in box.children if file_name not in row.children[1].description]
    
    delete_btn.on_click(delete_image)
    
    # 把图片和按钮放在同一行
    content_row = widgets.HBox([img_display, delete_btn])
    content_rows.append(content_row)

box.children = content_rows
display(box)
  • 点击单元格左侧的运行按钮(▶️),等待代码执行完毕

4. 查看并删除图片

  • 运行完成后,页面会显示所有图片的缩略图,每张图旁配有红色删除按钮
  • 点击按钮即可直接删除对应图片,下方控制台会提示删除成功
  • 如果删除后要刷新列表,重新运行一遍代码即可

注意事项

  • 代码中的width=200可根据需求调整,数值越大缩略图尺寸越大
  • 代码仅显示当前目录的图片,若要查看子文件夹的图片,需先进入对应子文件夹再运行代码
  • 删除操作不可逆,点击前请确认无需保留该图片

内容的提问来源于stack exchange,提问作者Ripul

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.29 06:36:08