python - 在 jupyter notebook 中将 HTML 表单转换为 python 代码
问题描述
我能够运行除此 colab 页面中的最后一个单元之外的所有单元。
“在示例图像上运行”部分中有一个表格。我如何使用脚本而不是那种形式?我正在使用不支持创建此类表单的 Jupyter 笔记本。
解决方案
如果你双击 colab 中的表单,你可以看到它后面的代码:
SAMPLE_IMAGE = 'image1' # @param ['image1', 'image2', 'image3']
IMAGE_URL = '' #@param {type:"string"}
_SAMPLE_URL = ('https://github.com/tensorflow/models/blob/master/research/'
'deeplab/g3doc/img/%s.jpg?raw=true')
def run_visualization(url):
"""Inferences DeepLab model and visualizes result."""
try:
f = urllib.request.urlopen(url)
jpeg_str = f.read()
original_im = Image.open(BytesIO(jpeg_str))
except IOError:
print('Cannot retrieve image. Please check url: ' + url)
return
print('running deeplab on image %s...' % url)
resized_im, seg_map = MODEL.run(original_im)
vis_segmentation(resized_im, seg_map)
image_url = IMAGE_URL or _SAMPLE_URL % SAMPLE_IMAGE
run_visualization(image_url)
如果您将此代码原样复制到您自己的 jupyter 实例中的新单元格中,您现在可以为@param
字段填充您喜欢的任何值并正常运行该单元格。
推荐阅读
- mysql - MySQL初学者查询帮助,电影和演员
- css - ionic3 星级插件,如何在星星中插入数字?
- java - Netty 是否只注册一个 ServerSocketChannel 到一个 NioEventLoop?
- asp.net-mvc - 覆盖 MVC 中的默认路由
- swiftui - ScrollView + DragGesture onChanged 冲突
- azure - 在 Azure.Messaging.ServiceBus 中使用主题筛选器
- ios - 更新 1 行时,我们如何决定选择 `NSBatchUpdateRequest` 或 `NSManagedObject`?
- wordpress - 搜索解决方案后,无法打开文件以阅读 wordpress 上的 All-in-One Migration
- php - 我的 laravel 程序中没有加载样式
- javascript - 猫鼬在所有子文档数组中查找