serialization

How to save / serialize a trained model in theano?

心不动则不痛 提交于 2020-01-01 09:12:31
问题 I saved the model as documented on loading and saving. # saving trained model f = file('models/simple_model.save', 'wb') cPickle.dump(ca, f, protocol=cPickle.HIGHEST_PROTOCOL) f.close() ca is a trained auto-encoder. It's a instance of class cA. From the script in which I build and save the model I can call ca.get_reconstructed_input(...) and ca.get_hidden_values(...) without any problem. In a different script I try to load the trained model. # loading the trained model model_file = file(

how to reattach singleton Spring beans upon deserialization

对着背影说爱祢 提交于 2020-01-01 09:10:10
问题 I want to reinject singleton-scoped dependencies into prototype Spring beans, after they have been deserialized. Say I've got a Process bean, which depends on a Repository bean. The Repository bean is a scoped as a singleton, but the Process bean is prototype-scoped. Periodically I serialize the Process, and then later deserialize it. class Process { private Repository repository; // getters, setters, etc. } I don't want to serialize and deserialize the Repository. Nor do I want to put

XmlSerializer replace xsi:type to node name

僤鯓⒐⒋嵵緔 提交于 2020-01-01 09:04:08
问题 Currently XmlSerializer produces the following structure: <config> <BaseType xsi:type="DerivedType1" /> <BaseType xsi:type="DerivedType2" /> </config> Is there any way to make it put type name into node: <config> <DerivedType1 /> <DerivedType2 /> </config> ? 回答1: Well you can just override the element name with the XmlElement Attrribute e.g. [XmlElement("DerivedType1")] public BaseType : DerivedType1 {get;set;} if will still put the xsi:type in though, and generate even greater confusion...

Why am I getting a serialization error?

左心房为你撑大大i 提交于 2020-01-01 08:46:07
问题 I have the following code: class Program { static void Main(string[] args) { string xml = @"<ArrayOfUserSetting> <UserSetting> <Value>Proposals</Value> <Name>LastGroup</Name> </UserSetting> <UserSetting> <Value>Visible</Value> <Name>WidgetsVisibility</Name> </UserSetting> </ArrayOfUserSetting>"; List<UserSetting> settings = GetObjFromXmlDocument<List<UserSetting>>(xml); } public static T GetObjFromXmlDocument<T>(string xml) { T customType; XmlSerializer serializer = new XmlSerializer(typeof(T

Why am I getting a serialization error?

别等时光非礼了梦想. 提交于 2020-01-01 08:45:58
问题 I have the following code: class Program { static void Main(string[] args) { string xml = @"<ArrayOfUserSetting> <UserSetting> <Value>Proposals</Value> <Name>LastGroup</Name> </UserSetting> <UserSetting> <Value>Visible</Value> <Name>WidgetsVisibility</Name> </UserSetting> </ArrayOfUserSetting>"; List<UserSetting> settings = GetObjFromXmlDocument<List<UserSetting>>(xml); } public static T GetObjFromXmlDocument<T>(string xml) { T customType; XmlSerializer serializer = new XmlSerializer(typeof(T

IDeserializationCallback vs OnDeserializedAttribute

孤人 提交于 2020-01-01 08:17:09
问题 As far as I understand, the IDeserializationCallback interface and the OnDeserialized event can both be used when an object needs to perform some task after being deserialized. IDeserializationCallback: [Serializable] public class Foo : IDeserializationCallback { public void OnDeserialization(object sender) { // initialize unserialized fields etc. } } OnDeserialized event: [Serializable] public class Foo { [OnDeserialized] public void OnDeserialized(StreamingContext context) { // initialize

Serializing textarea with wrap=“hard” doesn't give line breaks

被刻印的时光 ゝ 提交于 2020-01-01 07:21:15
问题 I have a textarea with "hard" wrapping: <textarea name="text" cols=5 wrap="hard">a b c d e f</textarea> When I serialize this textarea with jquery I get: text="a+b+c+d+e+f" Here is a fiddle. The problem is that I want to get the line breaks from the textarea. If I actually submit the form, then on the server I see the form come in with the proper line breaks. But I'd like to be able to get the line breaks without having to reload the page. I've already tried using the jquery form plugin with

What's the difference between Serialization and simply store the object on disk?

不羁的心 提交于 2020-01-01 07:06:42
问题 I am confused about this. Since when doing implementation of Serializable class, we need to use classes like FileOutputStream , ObjectOutputStream or something like that. Then why not we just use those classes to do things like output a object to a file and input a object from a file to maintain the status of a object directly? Why should we first implement Serializable and then do the same thing? 回答1: Understand it like this... Serializable is marker interface which denotes that the object

Protobuf.NET using

谁都会走 提交于 2020-01-01 06:54:31
问题 Need to send some data between managed c# and unmanaged c++. After some research I tried to use Protobuf.NET. I'm not sure if I understand functionality of ProtoBuf... Build a type definition in Proto. I need this type definition in both projects c++ and c# Use the command-line tool "protogen.exe" to get an .cs file and .cpp, .h from the type definition Copy the .cs files into my c# project and the .cpp, .h in my c++ solution. Seems I'm to stupid to to solve this. Here are my problem and

protobuf-net implicit contracts

…衆ロ難τιáo~ 提交于 2020-01-01 06:54:11
问题 Does anyone have a working example where protobuf-net can be used as a drop-in replacement for BinaryFormatter? Is that even possible? Actually I just need a serializer for one message type which looks like public class A { public B[] Bs { get;set; } public C[] Cs { get;set; } } All types are defined in a different assembly and have a lot of properties. Is there an option to automatically generate proto contracts with all public properties included, for class A and other used types (B, C), so