LibCinder: Default Variable Names for Shader Parameters - c++

I've been working through the
OpenGL guide for libCinder, in particular the shaders section.
Unfortunately, libCinder doesn't use the OpenGL variable names for default inputs to vertex and fragment shaders. E.g., gl_position is remapped to ciPosition.
Can anyone provide a list with a mapping from OpenGL to libCinder input variable names?

This is not the cleanest way, but you can see them inside the source code here:
sDefaultAttribNameToSemanticMap["ciPosition"] = geom::Attrib::POSITION;
sDefaultAttribNameToSemanticMap["ciNormal"] = geom::Attrib::NORMAL;
sDefaultAttribNameToSemanticMap["ciTangent"] = geom::Attrib::TANGENT;
sDefaultAttribNameToSemanticMap["ciBitangent"] = geom::Attrib::BITANGENT;
sDefaultAttribNameToSemanticMap["ciTexCoord0"] = geom::Attrib::TEX_COORD_0;
sDefaultAttribNameToSemanticMap["ciTexCoord1"] = geom::Attrib::TEX_COORD_1;
sDefaultAttribNameToSemanticMap["ciTexCoord2"] = geom::Attrib::TEX_COORD_2;
sDefaultAttribNameToSemanticMap["ciTexCoord3"] = geom::Attrib::TEX_COORD_3;
sDefaultAttribNameToSemanticMap["ciColor"] = geom::Attrib::COLOR;
sDefaultAttribNameToSemanticMap["ciBoneIndex"] = geom::Attrib::BONE_INDEX;
sDefaultAttribNameToSemanticMap["ciBoneWeight"] = geom::Attrib::BONE_WEIGHT;
And also:
sDefaultUniformNameToSemanticMap["ciModelMatrix"] = UNIFORM_MODEL_MATRIX;
sDefaultUniformNameToSemanticMap["ciModelMatrixInverse"] = UNIFORM_MODEL_MATRIX_INVERSE;
sDefaultUniformNameToSemanticMap["ciModelMatrixInverseTranspose"] = UNIFORM_MODEL_MATRIX_INVERSE_TRANSPOSE;
sDefaultUniformNameToSemanticMap["ciViewMatrix"] = UNIFORM_VIEW_MATRIX;
sDefaultUniformNameToSemanticMap["ciViewMatrixInverse"] = UNIFORM_VIEW_MATRIX_INVERSE;
sDefaultUniformNameToSemanticMap["ciModelView"] = UNIFORM_MODEL_VIEW;
sDefaultUniformNameToSemanticMap["ciModelViewInverse"] = UNIFORM_MODEL_VIEW_INVERSE;
sDefaultUniformNameToSemanticMap["ciModelViewInverseTranspose"] = UNIFORM_MODEL_VIEW_INVERSE_TRANSPOSE;
sDefaultUniformNameToSemanticMap["ciModelViewProjection"] = UNIFORM_MODEL_VIEW_PROJECTION;
sDefaultUniformNameToSemanticMap["ciModelViewProjectionInverse"] = UNIFORM_MODEL_VIEW_PROJECTION_INVERSE;
sDefaultUniformNameToSemanticMap["ciProjectionMatrix"] = UNIFORM_PROJECTION_MATRIX;
sDefaultUniformNameToSemanticMap["ciProjectionMatrixInverse"] = UNIFORM_PROJECTION_MATRIX_INVERSE;
sDefaultUniformNameToSemanticMap["ciViewProjection"] = UNIFORM_VIEW_PROJECTION;
sDefaultUniformNameToSemanticMap["ciNormalMatrix"] = UNIFORM_NORMAL_MATRIX;
sDefaultUniformNameToSemanticMap["ciViewportMatrix"] = UNIFORM_VIEWPORT_MATRIX;
sDefaultUniformNameToSemanticMap["ciWindowSize"] = UNIFORM_WINDOW_SIZE;
sDefaultUniformNameToSemanticMap["ciElapsedSeconds"] = UNIFORM_ELAPSED_SECONDS;

Related

Using Vulkan memory allocator with Volk

I'm currently trying to use Vulkan memory allocator with the meta loader Volk
here is the link of the two: https://github.com/zeux/volk
https://gpuopen.com/vulkan-memory-allocator/
But I have trouble with creating the VmaAllocator, here is my code:
void VulkApp::Init(PipelineFlags t_Conf, entt::registry& t_reg)
{
volkInitialize();
WindowProps props = {};
props.Height = 600;
props.Width = 800;
props.Title = "Engine";
currentWindow = EngWindow::Create(props);
//Create all physical, logical, instance for vulkan
Prepare();
VolkDeviceTable test;
volkLoadDeviceTable(&test, m_LogicalDevice->GetVkDevice());
VmaAllocatorCreateInfo allocatorCreateInfo = {};
allocatorCreateInfo.vulkanApiVersion = VK_API_VERSION_1_2;
allocatorCreateInfo.physicalDevice = m_PhysicalDevice->GetVkPhysicalDevice();
allocatorCreateInfo.device = m_LogicalDevice->GetVkDevice();
allocatorCreateInfo.instance = m_Instance->GetRawVkInstance();
allocatorCreateInfo.pVulkanFunctions = reinterpret_cast<const VmaVulkanFunctions*> (&test);
VmaAllocator allocator;
vmaCreateAllocator(&allocatorCreateInfo, &allocator);
BuildRenderPipelines(t_Conf, t_reg);
}
void VulkApp::Prepare()
{
m_Instance = std::make_unique<VulkInst>();
volkLoadInstance(m_Instance->GetRawVkInstance());
currentWindow->CreateSurface(m_Instance->GetRawVkInstance(), &m_Surface);
m_PhysicalDevice = std::make_unique<PhysicalDevice>(*m_Instance);
m_LogicalDevice = std::make_unique<LogicalDevice>(*m_Instance, *m_PhysicalDevice, m_Surface);
volkLoadDevice(m_LogicalDevice->GetVkDevice());
m_SwapChain = std::make_unique<SwapChain>(ChooseSwapExtent(), *m_LogicalDevice, *m_PhysicalDevice, m_Surface);
GraphicsHelpers::CreateCommandPool(m_CommandPool, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT); //TODO: added Transient bit
CreateFrameSyncResources();
/*
Create Camera
*/
BuildSwapChainResources();
}
I don't have any error when i build, but when i execute, the VmaCreateAllocator return an error:
Exception raised at 0x00007FFAB0CD836B (VkLayer_khronos_validation.dll) in My_Game.exe : 0xC0000005 : access violation reading location 0x0000000000000120.
Not very useful, but it stops on the line 14082 of the file vk_mem_alloc.h:
(*m_VulkanFunctions.vkGetPhysicalDeviceMemoryProperties)(m_PhysicalDevice, &m_MemProps);
The program check all the vulkan validation function so my vulkan function table must be good. But still the allocation fail.
I'm sorry i don't put a 'minimal' code, but with vulkan, even the minimum is really long. So, as a first test, maybe some of you have an insight of the error?
If you use a loader like Volk, you need to provide all memory related Vulkan function pointers used by VMA yourself.
This is done via the pVulkanFunctions member of the VmaAllocatorCreateInfo structure.
So when creating your VmaAllactor you set the function pointer in that to those fetched via Volk like this:
VmaVulkanFunctions vma_vulkan_func{};
vma_vulkan_func.vkAllocateMemory = vkAllocateMemory;
vma_vulkan_func.vkBindBufferMemory = vkBindBufferMemory;
vma_vulkan_func.vkBindImageMemory = vkBindImageMemory;
vma_vulkan_func.vkCreateBuffer = vkCreateBuffer;
vma_vulkan_func.vkCreateImage = vkCreateImage;
vma_vulkan_func.vkDestroyBuffer = vkDestroyBuffer;
vma_vulkan_func.vkDestroyImage = vkDestroyImage;
vma_vulkan_func.vkFlushMappedMemoryRanges = vkFlushMappedMemoryRanges;
vma_vulkan_func.vkFreeMemory = vkFreeMemory;
vma_vulkan_func.vkGetBufferMemoryRequirements = vkGetBufferMemoryRequirements;
vma_vulkan_func.vkGetImageMemoryRequirements = vkGetImageMemoryRequirements;
vma_vulkan_func.vkGetPhysicalDeviceMemoryProperties = vkGetPhysicalDeviceMemoryProperties;
vma_vulkan_func.vkGetPhysicalDeviceProperties = vkGetPhysicalDeviceProperties;
vma_vulkan_func.vkInvalidateMappedMemoryRanges = vkInvalidateMappedMemoryRanges;
vma_vulkan_func.vkMapMemory = vkMapMemory;
vma_vulkan_func.vkUnmapMemory = vkUnmapMemory;
vma_vulkan_func.vkCmdCopyBuffer = vkCmdCopyBuffer;
And then pass those to the create info:
VmaAllocatorCreateInfo allocator_info{};
...
allocator_info.pVulkanFunctions = &vma_vulkan_func;

GAN discriminator detach

Hello, I am new to the GANs. I wanted to ask why do we need to use detach() in the discriminator. I highlighted it in red. It is a part from Cyclegan by Alladdin person Github. Thank you for response.
with torch.cuda.amp.autocast():
fake_horse = gen_H(zebra) # generating fake horse
D_H_real = disc_H(horse) # classifying real horse
D_H_fake = ***disc_H(fake_horse.detach())***
H_reals += D_H_real.mean().item()
H_fakes += D_H_fake.mean().item()
D_H_real_loss = mse(D_H_real, torch.ones_like(D_H_real))
D_H_fake_loss = mse(D_H_fake, torch.zeros_like(D_H_fake))
D_H_loss = D_H_real_loss + D_H_fake_loss
fake_zebra = gen_Z(horse)
D_Z_real = disc_Z(zebra)
D_Z_fake = disc_Z(fake_zebra.detach())
D_Z_real_loss = mse(D_Z_real, torch.ones_like(D_Z_real))
D_Z_fake_loss = mse(D_Z_fake, torch.zeros_like(D_Z_fake))
D_Z_loss = D_Z_real_loss + D_Z_fake_loss
# put it togethor
D_loss = (D_H_loss + D_Z_loss)/2

How to call AWS Cloudfront Update-CFDistribution Powershell Cmdlet

I have written the script to change the origin path" of a specific origin on a specific distribution in CloudFront. After changing the path I am getting errors when trying to update the distribution with the changes. I do not want to change anything else on the distribution besides the "origin path", so how do I call Update-CFDistribution to make these changes ideally without having to set every parameter (future updates to the API may cause this script to fail or even worst make incomplete modifications)?
$distributions = Get-CFDistributionList
foreach($distribution in $distributions) {
if($distribution.Id -eq "$CloudfrontDistributionId") {
foreach ($origin in $distribution.Origins) {
foreach($item in $origin.Items) {
if($item.Id -eq "OriginName") {
$item.OriginPath = "/$($S3BucketPrefix)"
Update-CFDistribution -Id $CloudfrontDistributionId -Origins_Item #($item)
}
}
}
}
}
Error
InvalidOperation: 5 validation errors detected: Value null at
'distributionConfig.defaultCacheBehavior' failed to satisfy
constraint: Member must not be null; Value null at
'distributionConfig.enabled' failed to satisfy constraint: Member must
not be null; Value null at 'distributionConfig.callerReference' failed
to satisfy constraint: Member must not be null; Value null at
'distributionConfig.origins.quantity' failed to satisfy constraint:
Member must not be null; Value at 'distributionConfig.comment' failed
to satisfy constraint: Member must not be null
I don't have the reputation to add just a comment so I'm having to put this as an answer, but it's better suited as a comment.
According to the documentation, there are a number of required fields when you issue an update, even if you're only trying to update one thing:
https://docs.aws.amazon.com/powershell/latest/reference/items/Update-CFDistribution.html
When you update a distribution, there are more required fields than
when you create a distribution. When you update your distribution by
using this API action, follow the steps here to get the current
configuration and then make your updates, to make sure that you
include all of the required fields.
I had the same issue and asked about it on the aws-tools-for-powershell Q&A. As far as I can tell, the answer is you just have to map all the properties. I took the time to do that today. In other PowerShell module contexts, I would expect you'd be able to just pipe in the object from a Get call with changes into an Update call and it would handle the parameter bindings. That doesn't work in this context. This is a known issue for a lot of aws-tools-for-powershell cmdlets according to aws-tools-for-powershell Issue #214.
Below is a snippet of the 66 mappings required to ensure you're updating all properties exactly as they were handed to you in the original Get call. It's possible fewer are actually required, but given I want an exact copy it felt safer to ensure all the data was available and let the API decide what could be dropped.
The etag thing is from: AWS PowerShell update CloudFront distribution
$distribution = Get-CFDistribution -Id $distributionFromList.Id
$etag = $AWSHistory.LastServiceResponse.ETag
$params = #{
Id = $distribution.Id
Verbose = $true
IfMatch = $etag
Aliases_Item = $distribution.DistributionConfig.Aliases.Items
Aliases_Quantity = $distribution.DistributionConfig.Aliases.Quantity
AllowedMethods_Item = $distribution.DistributionConfig.DefaultCacheBehavior.AllowedMethods.Items
AllowedMethods_Quantity = $distribution.DistributionConfig.DefaultCacheBehavior.AllowedMethods.Quantity
CacheBehaviors_Item = $distribution.DistributionConfig.CacheBehaviors.Items
CacheBehaviors_Quantity = $distribution.DistributionConfig.CacheBehaviors.Quantity
CachedMethods_Item = $distribution.DistributionConfig.DefaultCacheBehavior.AllowedMethods.CachedMethods.Items
CachedMethods_Quantity = $distribution.DistributionConfig.DefaultCacheBehavior.AllowedMethods.CachedMethods.Quantity
Cookies_Forward = $distribution.DistributionConfig.DefaultCacheBehavior.ForwardedValues.Cookies.Forward
CustomErrorResponses_Item = $distribution.DistributionConfig.CustomErrorResponses.Items
CustomErrorResponses_Quantity = $distribution.DistributionConfig.CustomErrorResponses.Quantity
DefaultCacheBehavior_CachePolicyId = $distribution.DistributionConfig.DefaultCacheBehavior.CachePolicyId
DefaultCacheBehavior_Compress = $distribution.DistributionConfig.DefaultCacheBehavior.Compress
DefaultCacheBehavior_DefaultTTL = $distribution.DistributionConfig.DefaultCacheBehavior.DefaultTTL
DefaultCacheBehavior_FieldLevelEncryptionId = $distribution.DistributionConfig.DefaultCacheBehavior.FieldLevelEncryptionId
DefaultCacheBehavior_MaxTTL = $distribution.DistributionConfig.DefaultCacheBehavior.MaxTTL
DefaultCacheBehavior_MinTTL = $distribution.DistributionConfig.DefaultCacheBehavior.MinTTL
DefaultCacheBehavior_OriginRequestPolicyId = $distribution.DistributionConfig.DefaultCacheBehavior.OriginRequestPolicyId
DefaultCacheBehavior_RealtimeLogConfigArn = $distribution.DistributionConfig.DefaultCacheBehavior.RealtimeLogConfigArn
DefaultCacheBehavior_ResponseHeadersPolicyId = $distribution.DistributionConfig.DefaultCacheBehavior.ResponseHeadersPolicyId
DefaultCacheBehavior_SmoothStreaming = $distribution.DistributionConfig.DefaultCacheBehavior.SmoothStreaming
DefaultCacheBehavior_TargetOriginId = $distribution.DistributionConfig.DefaultCacheBehavior.TargetOriginId
DefaultCacheBehavior_ViewerProtocolPolicy = $distribution.DistributionConfig.DefaultCacheBehavior.ViewerProtocolPolicy
DistributionConfig_CallerReference = $distribution.DistributionConfig.CallerReference
DistributionConfig_Comment = $distribution.DistributionConfig.Comment
DistributionConfig_DefaultRootObject = $distribution.DistributionConfig.DefaultRootObject
DistributionConfig_Enabled = $distribution.DistributionConfig.Enabled
DistributionConfig_HttpVersion = $distribution.DistributionConfig.HttpVersion
DistributionConfig_IsIPV6Enabled = $distribution.DistributionConfig.IsIPV6Enabled
DistributionConfig_PriceClass = $distribution.DistributionConfig.PriceClass
DistributionConfig_WebACLId = $distribution.DistributionConfig.WebACLId
ForwardedValues_QueryString = $distribution.DistributionConfig.DefaultCacheBehavior.ForwardedValues.QueryString
FunctionAssociations_Item = $distribution.DistributionConfig.DefaultCacheBehavior.FunctionAssociations.Items
FunctionAssociations_Quantity = $distribution.DistributionConfig.DefaultCacheBehavior.FunctionAssociations.Quantity
GeoRestriction_Item = $distribution.DistributionConfig.Restrictions.GeoRestriction.Items
GeoRestriction_Quantity = $distribution.DistributionConfig.Restrictions.GeoRestriction.Quantity
GeoRestriction_RestrictionType = $distribution.DistributionConfig.Restrictions.GeoRestriction.RestrictionType
Headers_Item = $distribution.DistributionConfig.DefaultCacheBehavior.ForwardedValues.Headers.Items
Headers_Quantity = $distribution.DistributionConfig.DefaultCacheBehavior.ForwardedValues.Headers.Quantity
LambdaFunctionAssociations_Item = $distribution.DistributionConfig.DefaultCacheBehavior.LambdaFunctionAssociations.Items
LambdaFunctionAssociations_Quantity = $distribution.DistributionConfig.DefaultCacheBehavior.LambdaFunctionAssociations.Quantity
Logging_Bucket = $distribution.DistributionConfig.Logging.Bucket
Logging_Enabled = $distribution.DistributionConfig.Logging.Enabled
Logging_IncludeCookie = $distribution.DistributionConfig.Logging.IncludeCookies
Logging_Prefix = $distribution.DistributionConfig.Logging.Prefix
OriginGroups_Item = $distribution.DistributionConfig.OriginGroups.Items
OriginGroups_Quantity = $distribution.DistributionConfig.OriginGroups.Quantity
Origins_Item = $distribution.DistributionConfig.Origins.Items
Origins_Quantity = $distribution.DistributionConfig.Origins.Quantity
QueryStringCacheKeys_Item = $distribution.DistributionConfig.DefaultCacheBehavior.ForwardedValues.QueryStringCacheKeys.Items
QueryStringCacheKeys_Quantity = $distribution.DistributionConfig.DefaultCacheBehavior.ForwardedValues.QueryStringCacheKeys.Quantity
TrustedKeyGroups_Enabled = $distribution.DistributionConfig.DefaultCacheBehavior.TrustedKeyGroups.Enabled
TrustedKeyGroups_Item = $distribution.DistributionConfig.DefaultCacheBehavior.TrustedKeyGroups.Items
TrustedKeyGroups_Quantity = $distribution.DistributionConfig.DefaultCacheBehavior.TrustedKeyGroups.Quantity
TrustedSigners_Enabled = $distribution.DistributionConfig.DefaultCacheBehavior.TrustedSigners.Enabled
TrustedSigners_Item = $distribution.DistributionConfig.DefaultCacheBehavior.TrustedSigners.Items
TrustedSigners_Quantity = $distribution.DistributionConfig.DefaultCacheBehavior.TrustedSigners.Quantity
ViewerCertificate_ACMCertificateArn = $distribution.DistributionConfig.ViewerCertificate.ACMCertificateArn
ViewerCertificate_Certificate = $distribution.DistributionConfig.ViewerCertificate.Certificate
ViewerCertificate_CertificateSource = $distribution.DistributionConfig.ViewerCertificate.CertificateSource
ViewerCertificate_CloudFrontDefaultCertificate = $distribution.DistributionConfig.ViewerCertificate.CloudFrontDefaultCertificate
ViewerCertificate_IAMCertificateId = $distribution.DistributionConfig.ViewerCertificate.IAMCertificateId
ViewerCertificate_MinimumProtocolVersion = $distribution.DistributionConfig.ViewerCertificate.MinimumProtocolVersion
ViewerCertificate_SSLSupportMethod = $distribution.DistributionConfig.ViewerCertificate.SSLSupportMethod
WhitelistedNames_Item = $distribution.DistributionConfig.DefaultCacheBehavior.ForwardedValues.Cookies.WhitelistedNames.Items
WhitelistedNames_Quantity = $distribution.DistributionConfig.DefaultCacheBehavior.ForwardedValues.Cookies.WhitelistedNames.Quantity
}
Update-CFDistribution #params -WhatIf

How to set rules for generic type parameters in VisualStudio?

The picture below shows the warning I keep getting in Visual Studio 2017:
I got this off some website and I have tried all sorts of things. Does anyone know how I can get rid of this?
Here is my the part of my .editorconfig related to naming:
###############################
# Naming Conventions #
###############################
# Style Definitions
dotnet_naming_style.pascal_case_style.capitalization = pascal_case
dotnet_naming_style.camel_case_style.capitalization = camel_case
dotnet_naming_style.I_prefix_style.required_prefix = I
dotnet_naming_style.I_prefix_style.capitalization = pascal_case
# Use PascalCase for constant fields
dotnet_naming_rule.constant_fields_should_be_pascal_case.severity = warning
dotnet_naming_rule.constant_fields_should_be_pascal_case.symbols = constant_fields
dotnet_naming_rule.constant_fields_should_be_pascal_case.style = pascal_case_style
dotnet_naming_symbols.constant_fields.applicable_kinds = field
dotnet_naming_symbols.constant_fields.applicable_accessibilities = *
dotnet_naming_symbols.constant_fields.required_modifiers = const
# Use PascalCase for public fields
dotnet_naming_rule.pascal_case_for_public_fields.severity = warning
dotnet_naming_rule.pascal_case_for_public_fields.symbols = public_fields
dotnet_naming_rule.pascal_case_for_public_fields.style = pascal_case_style
dotnet_naming_symbols.public_fields.applicable_kinds = field
dotnet_naming_symbols.public_fields.applicable_accessibilities = public
# Interfaces must be PascalCase and have an I prefix
dotnet_naming_rule.interfaces_start_with_I.severity = warning
dotnet_naming_rule.interfaces_start_with_I.symbols = any_interface
dotnet_naming_rule.interfaces_start_with_I.style = I_prefix_style
dotnet_naming_symbols.any_interface.applicable_accessibilities = *
dotnet_naming_symbols.any_interface.applicable_kinds = interface
# Classes, structs, methods, enums, events, properties, namespaces, delegates must be PascalCase
dotnet_naming_rule.general_naming.severity = warning
dotnet_naming_rule.general_naming.symbols = general
dotnet_naming_rule.general_naming.style = pascal_case_style
dotnet_naming_symbols.general.applicable_kinds = class,struct,enum,property,method,event,namespace,delegate
dotnet_naming_symbols.general.applicable_accessibilities = *
# Everything else is camelCase
dotnet_naming_rule.everything_else_naming.severity = warning
dotnet_naming_rule.everything_else_naming.symbols = everything_else
dotnet_naming_rule.everything_else_naming.style = camel_case_style
dotnet_naming_symbols.everything_else.applicable_kinds = *
dotnet_naming_symbols.everything_else.applicable_accessibilities = *
# prefix_type_parameters_with_t_style - Generic Type Parameters must be PascalCase and the first character must be a 'T'
dotnet_naming_style.prefix_type_parameters_with_t_style.capitalization = pascal_case
dotnet_naming_style.prefix_type_parameters_with_t_style.required_prefix = T
You can get nice set of rules from here.

How exactly is tensorflow.control_dependecy applied?

self.solver = 'adam'
if self.solver == 'adam':
optimizer = tf.train.AdamOptimizer(self.learning_rate_init)
if self.solver == 'sgd_nestrov':
optimizer = tf.train.MomentumOptimizer(learning_rate = self.learning_rate_init, momentum = self.momentum, \
use_nesterov = True)
gradients, variables = zip(*optimizer.compute_gradients(self.loss))
clipped_gradients, self.global_norm = tf.clip_by_global_norm(gradients, self.max_grad_norm)
update_ops_ = tf.get_collection(tf.GraphKeys.UPDATE_OPS)
optimizer_op = optimizer.apply_gradients(zip(clipped_gradients, variables))
control_ops = tf.group([self.ema_op] + update_ops_)
with tf.control_dependencies([optimizer_op]):
self.optimizer = control_ops
i call self.optimizer with the session
The code above is not updating the gradients. However if i change the control dependencies part of the code to the one below it works perfectly fine except that it misses out on a final exponential moving average (self.ema_op) update, which is not desirable to me:
self.solver = 'adam'
if self.solver == 'adam':
optimizer = tf.train.AdamOptimizer(self.learning_rate_init)
if self.solver == 'sgd_nestrov':
optimizer = tf.train.MomentumOptimizer(learning_rate = self.learning_rate_init, momentum = self.momentum, \
use_nesterov = True)
gradients, variables = zip(*optimizer.compute_gradients(self.loss))
clipped_gradients, self.global_norm = tf.clip_by_global_norm(gradients, self.max_grad_norm)
update_ops_ = tf.get_collection(tf.GraphKeys.UPDATE_OPS)
optimizer_op = optimizer.apply_gradients(zip(clipped_gradients, variables))
control_ops = tf.group([self.ema_op] + update_ops_)
# with tf.control_dependencies(optimizer_op):
# self.optimizer = control_ops
with tf.control_dependencies([self.ema_op] + update_ops_):
self.optimizer = optimizer.apply_gradients(zip(clipped_gradients, variables))
Please tell me what am i missing?
You need to define the tensorflow operations under the with statement, not just set the variable. Doing self.optimizer = control_ops has no effect because you did not create any tensorflow operations.
Without fully understanding your problem I think you want something like this:
with tf.control_dependencies(optimizer_op):
control_ops = tf.group([self.ema_op] + update_ops_)
self.optimizer = control_ops
The with statement enters a block, under which any new ops you create in tensorflow will be dependent upon optimizer_op in this case.