René's URL Explorer Experiment


Title: Saving and Loading model errors · Issue #25 · pythonlessons/mltu · GitHub

Open Graph Title: Saving and Loading model errors · Issue #25 · pythonlessons/mltu

X Title: Saving and Loading model errors · Issue #25 · pythonlessons/mltu

Description: Hi, I am trying to train my model on my database according to the tutorial and sometimes the training takes quite a long time so I wanted to load the model saved by callback using this code: if os.path.exists("Model/model.h5"): HTR_Model...

Open Graph Description: Hi, I am trying to train my model on my database according to the tutorial and sometimes the training takes quite a long time so I wanted to load the model saved by callback using this code: if os....

X Description: Hi, I am trying to train my model on my database according to the tutorial and sometimes the training takes quite a long time so I wanted to load the model saved by callback using this code: if os....

Opengraph URL: https://github.com/pythonlessons/mltu/issues/25

X: @github

direct link

Domain: github.com

IPv4 address: 140.82.114.4


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Saving and Loading model errors","articleBody":"Hi,\r\n I am trying to train my model on my database according to the tutorial and sometimes the training takes quite a long time so I wanted to load the model saved by callback using this code:\r\n```\r\n        if os.path.exists(\"Model/model.h5\"):\r\n            HTR_Model = load_model(\"Model/model.h5\")\r\n            new_model = False\r\n        else:\r\n            img_shape = (self.height, self.width, 3)\r\n            HTR_Model = self.HTR_Model(img_shape, characters_num, vocab)\r\n            HTR_Model.compile_model()\r\n            HTR_Model.summary(line_length=110)\r\n            new_model = True\r\n```\r\nAnd then continue training with this code:\r\n```\r\n        earlystopper = EarlyStopping(monitor='val_CER', patience=20, verbose=1, mode='min')\r\n        checkpoint = ModelCheckpoint(\"Model/model.h5\", monitor='val_CER', verbose=1, save_best_only=True, mode='min')\r\n        trainLogger = TrainLogger(\"Model\")\r\n        tb_callback = TensorBoard('Model/logs', update_freq=1)\r\n        reduceLROnPlat = ReduceLROnPlateau(monitor='val_CER', factor=0.9, min_delta=1e-10, patience=10, verbose=1,\r\n                                           mode='auto')\r\n        model2onnx = Model2onnx(\"Model/model.h5\")\r\n\r\n        if new_model is True:\r\n            HTR_Model.train(training_data,\r\n                            val_data,\r\n                            epochs=1000,\r\n                            workers=20,\r\n                            callbacks=[earlystopper, checkpoint, trainLogger, reduceLROnPlat, tb_callback, model2onnx])\r\n        else:\r\n            HTR_Model.fit(training_data,\r\n                          validation_data=val_data,\r\n                          epochs=1000,\r\n                          workers=20,\r\n                          callbacks=[earlystopper, checkpoint, trainLogger, reduceLROnPlat, tb_callback, model2onnx],\r\n                          )\r\n```\r\n\r\nUnfortunately I encountered the following error:\r\n`ValueError: Unknown loss function: CTCloss. Please ensure this object is passed to the custom_objects argument.`\r\n\r\nSo I tried to add this argument like this:\r\n```\r\nHTR_Model = load_model(\"Model/model.h5\", custom_objects={'CTCloss': CTCloss})\r\n```\r\nBut It didn't work and I got this error:\r\n`TypeError: CTCloss.__init__() got an unexpected keyword argument reduction`\r\n\r\nI couldn't solve it so I started looking for other ways to load the model. This time I tried to do it by saving the file in .tf format and load it without custom_objects argument and it caused an error:\r\n`Unable to restore custom object of type _tf_keras_metric. Please make sure that any custom layers are included in the custom_objects arg when calling load_model() and make sure that all layers implement get_config and from_config.`\r\n\r\nAfter that I added argument like this:\r\n```\r\nHTR_Model = load_model(\"Model/model.tf\", custom_objects={'CERMetric': CERMetric(vocabulary=vocab), 'WERMetric': WERMetric(vocabulary=vocab)})\r\n```\r\nAnd the error was \r\n`TypeError: CERMetric.__init__() missing 1 required positional argument: 'vocabulary'`\r\nEven though I used this argument. The only thing that works is this code:\r\n```\r\nHTR_Model = load_model(\"Model/model.h5\", compile=False)\r\nHTR_Model.compile(loss=CTCloss(), metrics=[CERMetric(vocabulary=vocab), WERMetric(vocabulary=vocab)], run_eagerly=False)\r\n```\r\nBut it doesn't seem to be loading all these weights. I also tried using BackupAndRestore and picked up where I left off but still couldn't see if it saves those weights and continues using them. So Is it possible to somehow load a saved model while training is interrupted and continue training it so that it stays in accordance with the tutorial? (For example, I have epoch 53 /1000 and I see that the best value yet was saved to the model.h5 file at 52 epoch so I stop learning and then I want to load the saved model at epoch 52 and continue from there)","author":{"url":"https://github.com/Pixel535","@type":"Person","name":"Pixel535"},"datePublished":"2023-08-01T18:44:39Z","url":"https://github.com/pythonlessons/mltu/issues/25"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:d31d84a4-4a8c-7337-0315-e761c3483e28
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id81FA:27A224:3B85E7:505361:6B0438B6
html-safe-nonce3bc195eed1475b5b31eae6442d46198c24522eccc0eb31db82b4e03b687e75b8
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MUZBOjI3QTIyNDozQjg1RTc6NTA1MzYxOjZCMDQzOEI2IiwidmlzaXRvcl9pZCI6IjgzNjY3OTc2MDM4MTU1Njk1OTAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmace4b2770d3f7a2e280f9852408859fd17a179909695c293efa0e09b4aeb6b77ad
hovercard-subject-tagissue:1831832328
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/pythonlessons/mltu/25/issue_layout
twitter:imagehttps://opengraph.githubassets.com/c9387da9540328e805c32df255331435c401ba9149df3ceef4131f834681fb12/pythonlessons/mltu/issues/25
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/c9387da9540328e805c32df255331435c401ba9149df3ceef4131f834681fb12/pythonlessons/mltu/issues/25
og:image:altHi, I am trying to train my model on my database according to the tutorial and sometimes the training takes quite a long time so I wanted to load the model saved by callback using this code: if os....
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamePixel535
hostnamegithub.com
expected-hostnamegithub.com
None9185ccfefd80c1ff2d9ddcdb0cd2becf46b5a1efbbf30741a895e4bb8de25e64
turbo-cache-controlno-preview
go-importgithub.com/pythonlessons/mltu git https://github.com/pythonlessons/mltu.git
octolytics-dimension-user_id43852392
octolytics-dimension-user_loginpythonlessons
octolytics-dimension-repository_id572996960
octolytics-dimension-repository_nwopythonlessons/mltu
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id572996960
octolytics-dimension-repository_network_root_nwopythonlessons/mltu
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release06dc448a76fe4751ac1db26524aefa3aa3e889a8
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/pythonlessons/mltu/issues/25#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpythonlessons%2Fmltu%2Fissues%2F25
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpythonlessons%2Fmltu%2Fissues%2F25
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=pythonlessons%2Fmltu
Reloadhttps://github.com/pythonlessons/mltu/issues/25
Reloadhttps://github.com/pythonlessons/mltu/issues/25
Reloadhttps://github.com/pythonlessons/mltu/issues/25
pythonlessonshttps://github.com/pythonlessons
mltuhttps://github.com/pythonlessons/mltu
Codehttps://github.com/pythonlessons/mltu
Issues22 (22)https://github.com/pythonlessons/mltu/issues
Pull requestshttps://github.com/pythonlessons/mltu/pulls
Actionshttps://github.com/pythonlessons/mltu/actions
Projectshttps://github.com/pythonlessons/mltu/projects
Security and qualityhttps://github.com/pythonlessons/mltu/security
Insightshttps://github.com/pythonlessons/mltu/pulse
https://github.com/pythonlessons/mltu
New issuehttps://github.com/login?return_to=https://github.com/pythonlessons/mltu/issues/25
New issuehttps://github.com/login?return_to=https://github.com/pythonlessons/mltu/issues/25
Saving and Loading model errorshttps://github.com/pythonlessons/mltu/issues/25#top
https://github.com/Pixel535
Pixel535https://github.com/Pixel535
on Aug 1, 2023https://github.com/pythonlessons/mltu/issues/25#issue-1831832328
https://github.com/pythonlessons
pythonlessonshttps://github.com/pythonlessons
on Aug 1, 2023https://github.com/pythonlessons/mltu/issues/25#issuecomment-1660918931
https://github.com/Pixel535
Pixel535https://github.com/Pixel535
on Aug 1, 2023https://github.com/pythonlessons/mltu/issues/25#issuecomment-1661034260
https://github.com/Pixel535
Pixel535https://github.com/Pixel535
on Aug 21, 2023https://github.com/pythonlessons/mltu/issues/25#issuecomment-1686931733
https://github.com/Pixel535/ScribbleScan---Engineering-thesishttps://github.com/Pixel535/ScribbleScan---Engineering-thesis
https://github.com/pythonlessons
pythonlessonshttps://github.com/pythonlessons
on Aug 22, 2023https://github.com/pythonlessons/mltu/issues/25#issuecomment-1687684378
https://github.com/Pixel535
Pixel535https://github.com/Pixel535
on Aug 22, 2023https://github.com/pythonlessons/mltu/issues/25#issuecomment-1688954972
https://github.com/pythonlessons
pythonlessonshttps://github.com/pythonlessons
on Aug 23, 2023https://github.com/pythonlessons/mltu/issues/25#issuecomment-1689451530
https://github.com/Pixel535
Pixel535https://github.com/Pixel535
on Aug 23, 2023https://github.com/pythonlessons/mltu/issues/25#issuecomment-1689613037
Sign up for freehttps://github.com/signup?return_to=https://github.com/pythonlessons/mltu/issues/25
Sign in to commenthttps://github.com/login?return_to=https://github.com/pythonlessons/mltu/issues/25
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Response headers:
Servergithub.com
Content-Typetext/html; charset=utf-8
Cache-Controlmax-age=0, private, must-revalidate

Viewport: width=device-width


URLs of crawlers that visited me.