tancik / StegaStamp

Invisible Hyperlinks in Physical Photographs
http://www.matthewtancik.com/stegastamp
MIT License
675 stars 191 forks source link

Savedmodel generate empty variables directory #22

Closed gslxr closed 3 years ago

gslxr commented 4 years ago

Excuse me,sir.Can you help me? I try to use the natural images (100000 images) from Set and retrain the model,but don’t know why the generated model's variables directory is empty and saved_model.pb file is really big ,and I try a lot ,many say it's the reason that the graph is "frozen" (i.e., all variables are converted to constant nodes in the graph), so there are no "variables" left in the computation and hence the directory is empty.I don't know how to solve this,and I really appreciate for your help. the code to generate model is below: with tf.Session(graph=tf.Graph()) as session: tf.import_graph_def(constant_graph_def, name='') tf.saved_model.simple_save(session, SAVED_MODELS + '/' + EXP_NAME, inputs={'secret': secret_pl, 'image': image_pl}, outputs={'stegastamp': deploy_hide_image_op, 'residual': residual_op, 'decoded': deploy_decoder_op})

tancik commented 4 years ago

I am a bit confused by your questions. When you run bash scripts/base.sh EXP_NAME does it not save out the model?

gslxr commented 4 years ago

yes, sir.I run bash scripts/base.sh EXP_NAME and it does can save the model. The saved things are checkpoints, logs and saved_models directory, checkpoints and logs are saved accurately. However, when I open the saved_models, I find the pretrained_stegastamp have pb file and variables. The thing is pb file quite large and the content of variables is empty. I think it's a little different from yours. so I ask you this question. thank you, sir.  -------- 原始邮件 --------发件人: Matthew Tancik notifications@github.com日期: 2020年8月20日周四 01:26收件人: tancik/StegaStamp StegaStamp@noreply.github.com抄送: gslxr 13512983683@163.com, Author author@noreply.github.com主 题: Re: [tancik/StegaStamp] Savedmodel generate empty variables directory (#22) I am a bit confused by your questions. When you run bash scripts/base.sh EXP_NAME does it not save out the model?

—You are receiving this because you authored the thread.Reply to this email directly, view it on GitHub, or unsubscribe.

edwardocano commented 4 years ago

Hi gslxr, i have the same proble. Did you solved it?

tancik commented 4 years ago

At the end of the training the model is saved here - https://github.com/tancik/StegaStamp/blob/de4e8ca27ad3cef5eabbe9d892fd6efa6eeced83/train.py#L216 Can you verify this line is run without error, if not, what is the error? Perhaps there is permission issues with your folders?

edwardocano commented 4 years ago

Yes, that line runs without problem. the problem is that my saved_model.pb has a size of 215.5 MB and your saved_model.pb is 241.8kb. Also my variables folder is empty. and your traned model has two files of 217 MB and 2.4kb.

tancik commented 4 years ago

Ahh, gotcha. What happens when you try to run your saved model? What error do you get?

edwardocano commented 4 years ago

I got this https://drive.google.com/file/d/1hHtizPeY8f4Spfkuahb8X2xZl_mt9-dy/view?usp=sharing this is the link of my trained model. I just change the size of the data to 50 bits.

Traceback (most recent call last): File "encode_image.py", line 93, in <module> main() File "encode_image.py", line 76, in main hidden_img, residual = sess.run([output_stegastamp, output_residual],feed_dict=feed_dict) File "/home/ed/Desktop/StegaStamp/virtualenv/lib/python3.7/site-packages/tensorflow_core/python/client/session.py", line 956, in run run_metadata_ptr) File "/home/ed/Desktop/StegaStamp/virtualenv/lib/python3.7/site-packages/tensorflow_core/python/client/session.py", line 1156, in _run (np_val.shape, subfeed_t.name, str(subfeed_t.get_shape()))) ValueError: Cannot feed value of shape (1, 100) for Tensor 'input_prep:0', which has shape '(?, 50)'

tancik commented 4 years ago

You are getting a shape error Cannot feed value of shape (1, 100) for Tensor 'input_prep:0', which has shape '(?, 50)' This isn't caused by the saved model issue you mentioned above. You need to pass your secret size as an argument to encode image. https://github.com/tancik/StegaStamp/blob/de4e8ca27ad3cef5eabbe9d892fd6efa6eeced83/encode_image.py#L22

edwardocano commented 4 years ago

Yes! i understand that part. python encode_image.py saved_models2/stegastamp_pretrained --image original.jpg --save_dir out/ --secret 12 --secret_size 50 This is the line i use. even if i write --secret_size 50 with your trained model. it does not show any error. where is the secret_size value used?

tancik commented 4 years ago

Ahh, yes that is an error on my part. Then encode_image.py requires the code to be of length 100. This function uses BCH codes with specific parameters to convert a string into a 100bit message. You must use a different error correcting code (or no error correcting) if you change the size of the message.

edwardocano commented 4 years ago

Could you share a explample of encode and decode without error correcting code?. Please.

tancik commented 4 years ago

I'm not going to be able to write out a full example, but I can give some pointers. For encoding, just change packet_binary to the 50 bit binary code you want to store. You can ignore all of the previous lines regarding BCH. https://github.com/tancik/StegaStamp/blob/8e4eeda30a4210c7e0bcf5b47c35a9bc734e9bfa/encode_image.py#L59

For decoding, https://github.com/tancik/StegaStamp/blob/8e4eeda30a4210c7e0bcf5b47c35a9bc734e9bfa/decode_image.py#L49 secret will contain your 50 bit message. All lines after can be ignored.

Also given that this is unrelated to the original issue, please create new issues for followup questions.

edwardocano commented 4 years ago

Thanks! I understand, I saw an example with a image encoded with 50 bits. So i tought you had an example.

gslxr commented 4 years ago

no,though it is empty,it also can use without error.

fujiaixin09 commented 3 years ago

no,though it is empty,it also can use without error.

Hi,gslxr,I also had this problem“ValueError: Cannot feed value of shape (1, 100) for Tensor 'input_prep:0', which has shape '(?, 20)'”,how did you solve it?

gslxr commented 3 years ago

你训练的时候,是把secret的长度设置为20了吧,在你输入命令—secret时,写为长度为20的位串

发送自 Windows 10 版邮件应用

发件人: fujiaixin09 发送时间: 2020年12月24日 9:38 收件人: tancik/StegaStamp 抄送: gslxr; State change 主题: Re: [tancik/StegaStamp] Savedmodel generate empty variables directory(#22)

no,though it is empty,it also can use without error. Hi,gslxr,I also had this problem“ValueError: Cannot feed value of shape (1, 100) for Tensor 'input_prep:0', which has shape '(?, 20)'”,how did you solve it? — You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub, or unsubscribe.

fujiaixin09 commented 3 years ago

您好!感谢您的回复!我现在还遇到一个问题,在利用我自己训练好的模型进行解码,并不能解出“out/3_hidden.png Failed to decode”,请问您有遇到这个问题吗?或许是我的模型有问题? 期待您的回复!祝您身体健康,万事如意!

------------------ 原始邮件 ------------------ 发件人: "tancik/StegaStamp" <notifications@github.com>; 发送时间: 2020年12月24日(星期四) 上午10:43 收件人: "tancik/StegaStamp"<StegaStamp@noreply.github.com>; 抄送: "🍂"<2531406843@qq.com>;"Comment"<comment@noreply.github.com>; 主题: Re: [tancik/StegaStamp] Savedmodel generate empty variables directory (#22)

你训练的时候,是把secret的长度设置为20了吧,在你输入命令—secret时,写为长度为20的位串

发送自 Windows 10 版邮件应用

发件人: fujiaixin09 发送时间: 2020年12月24日 9:38 收件人: tancik/StegaStamp 抄送: gslxr; State change 主题: Re: [tancik/StegaStamp] Savedmodel generate empty variables directory(#22)

no,though it is empty,it also can use without error. Hi,gslxr,I also had this problem“ValueError: Cannot feed value of shape (1, 100) for Tensor 'input_prep:0', which has shape '(?, 20)'”,how did you solve it? — You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub, or unsubscribe.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

gslxr commented 3 years ago

不是模型训练的问题,是由于编码图像损失过大,模型无法正确拟合信息,进行解码。 发件人: fujiaixin09 发送时间: 2020年12月24日 11:09 收件人: tancik/StegaStamp 抄送: gslxr; State change 主题: Re: [tancik/StegaStamp] Savedmodel generate empty variables directory(#22)

您好!感谢您的回复!我现在还遇到一个问题,在利用我自己训练好的模型进行解码,并不能解出“out/3_hidden.png Failed to decode”,请问您有遇到这个问题吗?或许是我的模型有问题? 期待您的回复!祝您身体健康,万事如意!

------------------ 原始邮件 ------------------ 发件人: "tancik/StegaStamp" <notifications@github.com>; 发送时间: 2020年12月24日(星期四) 上午10:43 收件人: "tancik/StegaStamp"<StegaStamp@noreply.github.com>; 抄送: "🍂"<2531406843@qq.com>;"Comment"<comment@noreply.github.com>; 主题: Re: [tancik/StegaStamp] Savedmodel generate empty variables directory (#22)

你训练的时候,是把secret的长度设置为20了吧,在你输入命令—secret时,写为长度为20的位串

发送自 Windows 10 版邮件应用

发件人: fujiaixin09 发送时间: 2020年12月24日 9:38 收件人: tancik/StegaStamp 抄送: gslxr; State change 主题: Re: [tancik/StegaStamp] Savedmodel generate empty variables directory(#22)

no,though it is empty,it also can use without error. Hi,gslxr,I also had this problem“ValueError: Cannot feed value of shape (1, 100) for Tensor 'input_prep:0', which has shape '(?, 20)'”,how did you solve it? — You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub, or unsubscribe.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe. — You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub, or unsubscribe.