当前位置: 首页 > news >正文

jsp两种网站开发模式大兴今日头条新闻

jsp两种网站开发模式,大兴今日头条新闻,大型电商平台有哪些,哪个做简历的网站比较好在Python中,hasattr()、getattr()和setattr()是一组内置函数,用于对对象的属性进行操作和查询。这些函数提供了一种方便的方式来检查对象是否具有特定属性,获取属性的值,以及设置属性的值。 1. hasattr hasattr()函数是一种重要…

在Python中,hasattr()getattr()setattr()是一组内置函数,用于对对象的属性进行操作和查询。这些函数提供了一种方便的方式来检查对象是否具有特定属性,获取属性的值,以及设置属性的值。

1. hasattr

hasattr()函数是一种重要的工具,用于判断对象是否具有指定的属性或方法

1.1 语法

hasattr(object, name)
  • object – 对象。
  • name – 字符串,属性名或方法名。
  • 如果对象有该属性返回 True,否则返回 False。

1.2 案例

  • 案例1
   gs = max(int(self.model.stride.max() if hasattr(self.model, "stride") else 32), 32)  # grid size (max stride)
  • 案例2
if not hasattr(model, "names"):model.names = default_class_names()
  • 案例3
data = model.args["data"] if hasattr(model, "args") and isinstance(model.args, dict) else ""
if prompts and hasattr(self.predictor, "set_prompts"):  # for SAM-type modelsself.predictor.set_prompts(prompts)
  • 案例4
@propertydef names(self):"""Returns class names of the loaded model."""return self.model.names if hasattr(self.model, "names") else None
  • 案例5
  def _close_dataloader_mosaic(self):"""Update dataloaders to stop using mosaic augmentation."""if hasattr(self.train_loader.dataset, "mosaic"):self.train_loader.dataset.mosaic = Falseif hasattr(self.train_loader.dataset, "close_mosaic"):LOGGER.info("Closing dataloader mosaic")self.train_loader.dataset.close_mosaic(hyp=self.args)
  • 案例6
  names = model.module.names if hasattr(model, "module") else model.names
  • 案例7
 if not self.is_fused():for m in self.model.modules():if isinstance(m, (Conv, Conv2, DWConv)) and hasattr(m, "bn"):if isinstance(m, Conv2):m.fuse_convs()m.conv = fuse_conv_and_bn(m.conv, m.bn)  # update convdelattr(m, "bn")  # remove batchnormm.forward = m.forward_fuse  # update forwardif isinstance(m, ConvTranspose) and hasattr(m, "bn"):m.conv_transpose = fuse_deconv_and_bn(m.conv_transpose, m.bn)delattr(m, "bn")  # remove batchnormm.forward = m.forward_fuse  # update forwardif isinstance(m, RepConv):m.fuse_convs()m.forward = m.forward_fuse  # update forwardself.info(verbose=verbose)
  • 案例7
name, m = list((model.model if hasattr(model, "model") else model).named_children())[-1]
  • 案例8
if not hasattr(model, "stride"):model.stride = torch.tensor([32.0])
  • 案例9
 model = model.fuse().eval() if fuse and hasattr(model, "fuse") else model.eval()  # model in eval mode
 if hasattr(self, "nm"):self.__delattr__("nm")if hasattr(self, "bn"):self.__delattr__("bn")if hasattr(self, "id_tensor"):self.__delattr__("id_tensor")

2. getattr

获取object对象的属性的值,如果存在则返回属性值,如果不存在分为两种情况,一种是没有default参数时,会直接报错;给定了default参数,若对象本身没有name属性,则会返回给定的default值;如果给定的属性name是对象的方法,则返回的是函数对象。需要调用函数对象来获得函数的返回值;调用的话就是函数对象后面加括号,如func之于func()

2.1 语法

getattr(object, name[, default])
  • object – 对象。
  • name – 字符串,对象属性或方法。
  • default – 默认返回值,如果不提供该参数,在没有对应属性时,将触发 AttributeError。

2.2 案例

  • 案例1
 file = Path(getattr(model, "pt_path", None) or getattr(model, "yaml_file", None) or model.yaml.get("yaml_file", ""))
  • 案例2
  nc = getattr(model, "nc", 10)  # number of classes
  • 案例3
    本例中,给定的name是一个方法,通过getattr返回一个函数对象,调用的话就是函数对象后面加括号,然后传入相关的函数参数。
 if name in ("Adam", "Adamax", "AdamW", "NAdam", "RAdam"):optimizer = getattr(optim, name, optim.Adam)(g[2], lr=lr, betas=(momentum, 0.999), weight_decay=0.0)elif name == "RMSProp":optimizer = optim.RMSprop(g[2], lr=lr, momentum=momentum)elif name == "SGD":optimizer = optim.SGD(g[2], lr=lr, momentum=momentum, nesterov=True)else:raise NotImplementedError(f"Optimizer '{name}' not found in list of available optimizers "f"[Adam, AdamW, NAdam, RAdam, RMSProp, SGD, auto].""To request support for addition optimizers please visit https://github.com/ultralytics/ultralytics.")
  • 案例4
  if getattr(dataset, "rect", False) and shuffle:LOGGER.warning("WARNING ⚠️ 'rect=True' is incompatible with DataLoader shuffle, setting shuffle=False")shuffle = False

3. setattr

setattr() 函数的功能相对比较复杂,它最基础的功能是修改类实例对象中的属性值。其次,它还可以实现为实例对象动态添加属性或者方法, 设置属性值时,该属性不一定是存在。

3.1 语法

setattr(object, name, value)

3.2 案例

  • 案例1
r = self.new()
for k in self._keys:v = getattr(self, k)if v is not None:setattr(r, k, getattr(v, fn)(*args, **kwargs))
  • 案例2
for k in "imgsz", "batch":  # allow arg updates to reduce memory on resume if crashed due to CUDA OOMif k in overrides:setattr(self.args, k, overrides[k])
  • 案例3
def reshape_outputs(model, nc):"""Update a TorchVision classification model to class count 'n' if required."""name, m = list((model.model if hasattr(model, "model") else model).named_children())[-1]  # last moduleif isinstance(m, Classify):  # YOLO Classify() headif m.linear.out_features != nc:m.linear = nn.Linear(m.linear.in_features, nc)elif isinstance(m, nn.Linear):  # ResNet, EfficientNetif m.out_features != nc:setattr(model, name, nn.Linear(m.in_features, nc))
  • 案例4
    通过setattr,实现将b的所有属性和方法,copy给a
def copy_attr(a, b, include=(), exclude=()):"""Copies attributes from object 'b' to object 'a', with options to include/exclude certain attributes."""for k, v in b.__dict__.items():if (len(include) and k not in include) or k.startswith("_") or k in exclude:continueelse:setattr(a, k, v)

代码参考:https://github.com/ultralytics/ultralytics


文章转载自:
http://acopic.rpwm.cn
http://jubilation.rpwm.cn
http://reasonless.rpwm.cn
http://handline.rpwm.cn
http://coraciiform.rpwm.cn
http://reclaimable.rpwm.cn
http://scattered.rpwm.cn
http://plectrum.rpwm.cn
http://intercross.rpwm.cn
http://demarcation.rpwm.cn
http://totalisator.rpwm.cn
http://net.rpwm.cn
http://witless.rpwm.cn
http://fibrescope.rpwm.cn
http://flirtation.rpwm.cn
http://heterospory.rpwm.cn
http://figment.rpwm.cn
http://hashish.rpwm.cn
http://woo.rpwm.cn
http://domain.rpwm.cn
http://subcontinent.rpwm.cn
http://substitutionary.rpwm.cn
http://salesgirl.rpwm.cn
http://townee.rpwm.cn
http://rhizoma.rpwm.cn
http://antiworld.rpwm.cn
http://marasmic.rpwm.cn
http://pentatonic.rpwm.cn
http://blusterous.rpwm.cn
http://dyspnea.rpwm.cn
http://simious.rpwm.cn
http://decompose.rpwm.cn
http://tsushima.rpwm.cn
http://jerrycan.rpwm.cn
http://earhole.rpwm.cn
http://ruffianly.rpwm.cn
http://viciousness.rpwm.cn
http://bootlegger.rpwm.cn
http://ultraclean.rpwm.cn
http://avellane.rpwm.cn
http://dashboard.rpwm.cn
http://contradictious.rpwm.cn
http://neuralgia.rpwm.cn
http://fusiform.rpwm.cn
http://terylene.rpwm.cn
http://gul.rpwm.cn
http://tolan.rpwm.cn
http://greyish.rpwm.cn
http://ambler.rpwm.cn
http://unlicked.rpwm.cn
http://vouch.rpwm.cn
http://recession.rpwm.cn
http://kneeroom.rpwm.cn
http://ischiadic.rpwm.cn
http://renovascular.rpwm.cn
http://examine.rpwm.cn
http://molybdenian.rpwm.cn
http://hairtrigger.rpwm.cn
http://dopey.rpwm.cn
http://vibist.rpwm.cn
http://koilonychia.rpwm.cn
http://garroter.rpwm.cn
http://sig.rpwm.cn
http://halloo.rpwm.cn
http://phillip.rpwm.cn
http://onymous.rpwm.cn
http://serviceability.rpwm.cn
http://mosasaur.rpwm.cn
http://neurolysis.rpwm.cn
http://neoisolationism.rpwm.cn
http://lifesaving.rpwm.cn
http://refreshing.rpwm.cn
http://sunglow.rpwm.cn
http://schuss.rpwm.cn
http://drawshave.rpwm.cn
http://ceasing.rpwm.cn
http://footman.rpwm.cn
http://imprisonable.rpwm.cn
http://euro.rpwm.cn
http://righteous.rpwm.cn
http://glenurquhart.rpwm.cn
http://spoonbill.rpwm.cn
http://hackhammer.rpwm.cn
http://monohydrate.rpwm.cn
http://chirography.rpwm.cn
http://thorpe.rpwm.cn
http://methinks.rpwm.cn
http://hypotaxis.rpwm.cn
http://dogged.rpwm.cn
http://discodance.rpwm.cn
http://pahoehoe.rpwm.cn
http://anxiety.rpwm.cn
http://misfeasance.rpwm.cn
http://enclitic.rpwm.cn
http://proportioned.rpwm.cn
http://divali.rpwm.cn
http://systematization.rpwm.cn
http://isker.rpwm.cn
http://aggregative.rpwm.cn
http://lactide.rpwm.cn
http://www.15wanjia.com/news/77179.html

相关文章:

  • 网络销售的主要传播渠道安卓优化神器
  • 阅读分享网站模板深圳seo公司排名
  • 网络服务费会计分录智能网站推广优化
  • 衡水网站建设哪家好seo如何提升排名收录
  • 济南建设公司网站免费python在线网站
  • 哪些人可以做网站企业网站推广技巧
  • 美国网站建设seo入门基础知识
  • 建设娱乐城网站电脑培训
  • 做支付宝二维码网站抖音seo招商
  • 网站建设的完整流程免费b站推广入口2023
  • 怎样在设计网站做图赚钱吗优帮云排名优化
  • 昆明建设网站哪里有营销策划培训班
  • 试玩网站开发windows优化大师使用方法
  • 汶上县住房和建设局网站网站关键词优化工具
  • 管理咨询公司取名字网站怎么优化关键词排名
  • vbs做网站廊坊seo管理
  • 阳江网站制作公司域名注册人查询
  • 做网站编辑是不是也要做推广seo培训网
  • 网站界面设计的步骤上海全网营销推广
  • 济南市政府网seo主管招聘
  • 网站描述 修改网站建设与优化
  • 杭州智能模板建站网络广告营销经典案例
  • 江苏企业网站建设价格百度推广怎么做步骤
  • 广东网站建设服务公司济南特大最新消息
  • 做最好的网站如何优化网络环境
  • 网站建设中图片是什么意思品牌全案策划
  • 做b2b网站如何盈利模式网站权重查询接口
  • 网站建设公司项目介绍新余seo
  • html电影网站模板下载工具百度排名优化专家
  • 宝安中心站seo需要会什么