运行代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;
namespace ConsoleApplication1
{
class Program
{
const string FILENAME = @"c:\temp\test.xml";
static void Main(string[] args)
{
XDocument oldDoc = XDocument.Load(FILENAME);
XElement oldNodes = oldDoc.Descendants("nodes").FirstOrDefault();
string header = "<?xml version=\"1.0\" encoding=\"utf-8\" ?><sensortree><nodes></nodes></sensortree>";
XDocument newDoc = XDocument.Parse(header);
XElement newNodes = newDoc.Descendants("nodes").FirstOrDefault();
GetTreeRecursively(oldNodes, newNodes);
}
static void GetTreeRecursively(XElement oldElement, XElement newElement)
{
string[] findTags = { "group", "probenode", "device", "sensor" };
List<XElement> oldChildren = oldElement.Elements().Where(x => findTags.Contains(x.Name.LocalName)).ToList();
foreach (XElement oldChild in oldChildren)
{
XElement newChild = new XElement(oldChild.Name.LocalName, new XAttribute("id", (string)oldChild.Attribute("id")));
newChild.Add(oldChild.Element("name"));
newChild.Add(oldChild.Element("id"));
newElement.Add(newChild);
GetTreeRecursively(oldChild, newChild);
}
}
}
}
和发生的错误
export_path= '/content/gdrive/My Drive'+ '\\model\\'+'20191003053122'
with tf.Session(graph=tf.Graph()) as sess:
tf.saved_model.loader.load(sess, ["myTag"], export_path)
graph = tf.get_default_graph()
我不了解的是,我之前设置了相同的路径(ValueError: The passed save_path is not a valid checkpoint: /content/gdrive/My Drive\model\20191003053122/variables/variables
),但是Google Colab仍然说该检查点无效。这是什么意思并且出了错?我还多次更改了两个路径(例如将export_path = '/content/gdrive/My Drive' +'\\model\\'+time.strftime("%Y%m%d%H%M%S",time.localtime())
替换为'/content/gdrive/My Drive'
)以确保它们彼此匹配,但没有帮助。
我想知道是否是因为代码
os.getcwd()+
不建议使用-如果是这种情况,我应该使用什么等效项?也许with tf.Session(graph=tf.Graph()) as sess:
tf.saved_model.loader.load(sess, ["myTag"], export_path)
graph = tf.get_default_graph()
?任何贡献表示赞赏。谢谢
答案 0 :(得分:0)
在Google Colab和Google云端硬盘之间似乎存在访问问题
您可以退后一步,确认您的Google驱动器是否已正确安装,并且能够通过Goole Colab读写文件。
这是要遵循的步骤:
导入并安装Google云端硬盘
from google.colab import drive
drive.mount('/content/gdrive')
验证您能够列出驱动器中或要写入的位置中的文件
!ls "/content/gdrive/My Drive"
在Google云端硬盘中写入文件
我已经使用"w"
来创建不存在的文件
Other file modes in Python open()
function
with open("/content/gdrive/My Drive/myFile.txt", "w") as file:
file.write("Your text goes here")
再次读取文件以检查写入文件是否正常!
!cat "/content/gdrive/My Drive/myFile.txt"
Image of my Google colab working code snippet
You can even check the official Goolge Colab notebook with steps here
希望这会有所帮助:)