python - 为什么我不能在 C# 中使用 ProcessStartInfo() 将参数传递给 python 文件
问题描述
我正在实现一个在 TensorFlow 上运行的图像分类应用程序。我能够使用 Python 成功获得所有结果,现在正在使用我熟悉的 C# 实现 GUI。我在这里使用示例。我的问题是我不能像在 Python 中那样传递参数,我在 python 文件旁边键入它们。
这就是我设置标题信息的方式
string cmd = @"c:\flowers\label_image.py";
string args = @"--input_layer=Placeholder --output_layer=final_result --image=c:/flower_photos/daisy/21652746_cc379e0eea_m.jpg";
start.FileName = @"C:\Users\pubud\AppData\Local\Programs\Python\Python36\python.exe";
start.Arguments = string.Format("\"{0}\" \"{1}\"", cmd, args);
当上面执行时,我得到
"c:\flowers\label_image.py" "--input_layer=Placeholder --output_layer=final_result --image=c:/flower_photos/daisy/21652746_cc379e0eea_m.jpg"
2019-01-05 08:55:25.369320: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
Traceback (most recent call last):
File "c:\flowers\label_image.py", line 127, in <module>
input_operation = graph.get_operation_by_name(input_name)
File "C:\Users\pubud\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\framework\ops.py", line 3618, in get_operation_by_name
return self.as_graph_element(name, allow_tensor=False, allow_operation=True)
File "C:\Users\pubud\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\framework\ops.py", line 3490, in as_graph_element
return self._as_graph_element_locked(obj, allow_tensor, allow_operation)
File "C:\Users\pubud\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\framework\ops.py", line 3544, in _as_graph_element_locked
(repr(name), types_str))
ValueError: Name 'import/Placeholder --output_layer=final_result --image=c:/flower_photos/daisy/21652746_cc379e0eea_m.jpg' appears to refer to a Tensor, not a Operation.
这里的问题是 label_image.py 不理解参数并尝试运行默认值。
但是,如果我删除参数并调用 label_image.py 并将默认值硬编码到 py 文件中,它的工作正常。
start.Arguments = string.Format("\"{0}\"", cmd);
为什么这不理解我的论点?
解决方案
以下提供的格式系统税导致错误。(它将“”传递给参数字符串)
start.Arguments = string.Format("\"{0}\" \"{1}\"", cmd, args);
所以改为如下:
start.Arguments = string.Format(@"{0} {1}", cmd, args);
它现在正在工作。
推荐阅读
- azure - 通过 REST API 添加自定义域会为 KeyVaultId 分配“NULL”值
- python - 熊猫层次结构数据框中的方差相关条件
- powerbi - 如何在 power bi 中创建一个基于国家/地区计算是和否值的度量
- javascript - 如果重新启动程序,node.js 中的集合是否会重置?
- google-cloud-platform - 扩展 Google Cloud Pull 订阅者
- scala - 除了 Spark Scala 的更好的替代品
- c# - http2 请求 docker 容器内存不断增加 - 不释放
- tsql - 将数据从 Azure Blob 存储导入 AzureSQL PaaS 的方法
- python - 我如何让乌龟对象与另一个对象面对相同的方向?
- python - Python regex 提取匹配字符串之间的字符串,包括匹配字符串