在这篇文章中,我们将带领您了解Timetogetsome128-bittypesintoMySQL?_MySQL的全貌,同时,我们还将为您介绍有关A2-04-10.MySQLDATATYPES-Mas
在这篇文章中,我们将带领您了解Time to get some 128-bit types into MySQL?_MySQL的全貌,同时,我们还将为您介绍有关A2-04-10.MySQL DATA TYPES-Mastering MySQL TIME Data Type、BAT批处理文件,脚本时间值%time:~0,2%%time:~3,2%%time:~6,2%的用法。、CNN ValueError:Shapes (10, 4) 和 (10, 128, 128, 4) 不兼容、CSS选择的使用--获取style=“color: rgba(0, 128, 128, 1)“的标签的知识,以帮助您更好地理解这个主题。
本文目录一览:- Time to get some 128-bit types into MySQL?_MySQL
- A2-04-10.MySQL DATA TYPES-Mastering MySQL TIME Data Type
- BAT批处理文件,脚本时间值%time:~0,2%%time:~3,2%%time:~6,2%的用法。
- CNN ValueError:Shapes (10, 4) 和 (10, 128, 128, 4) 不兼容
- CSS选择的使用--获取style=“color: rgba(0, 128, 128, 1)“的标签
Time to get some 128-bit types into MySQL?_MySQL
i think that getting 128-bit integer types into mysql would be good. there are a few use cases for this and right now we have to work around them. that should not be necessary. while not essential they would make things easier.
The headline is easy to understand, but is this really needed?
First we need to look to see where this might be used. I can think of three different 128-bit types which are missing at the moment:
- IPv6 addresses
- uuid values
- a bigger value than (signed) bigint [64-bit numbers]
IPv6 Addresses
IPv6 addresses are 128-bit numbers, and having a native way to store them would be really helpful. Given this also includes an IPv4 representation then for those people who store IP addresses (client connections and other things) such a native type would be much better than the typical unsigned int or binary(4) which you might be using now. Is this an IPv4 address? Well it might be, but it also might not be. The same applies to IPv6, and having a real IPv6 type makes this knowledge more explicit.
MySQL already provides support routines for IPv4 (even if the type does not exist) such asINET_ATON(), INET_NTOA()so a similar set of routines would be needed to support this type, converting between their text and numeric representation and also for converting between IPv4 and IPv6.
UUID Values
MySQL itself uses UUID values in 5.6 and above as the server_uuid, but it’s stored or seems to be as a string. Other software (MEM is a good example) also uses UUID values in various places.
Have a look on search engines for MySQL and UUID and you see lots of questions on how to best store these values in MySQL. So there is already a demand for this, and no good answers as far as I can see.
One common concern I have currently when storing such values as binary(16) is that the values are hard to visualise, especially if used as a primary key, and also from the DBA’s point of view who may want to “manually” access or modify data it is not possible to do something similar to SELECT name FROM servers WHERE uuid = ‘cd2180ae-9b94-11e2-b407-e83935c12500′, as this just does not work. Casting could make this work magically but right now it’s much harder than it should be. There is not a single UUID format but the basics are the same and if we had a uuid format any supporting routines (which would be needed) would be able to convert as needed.
Signed or unsigned integers
Yes, the (signed or unsigned) bigint type gives us 64-bits and that allows for huge numbers but one size bigger matches the use cases above, so it’s good to be able to convert between them depending on the usage. That is if we’re going to have IPv6 and UUID type values, it makes sense to allow an integer equivalent representation and sometimes this might be needed when stripping out parts of a uuid, or parts of an IPv6 address. The name of this type should be something a little better than we’ve seen before sohugeint (unsigned)would notbe what I would suggest. Something as simple asint128 (unsigned)would be much easier to understand.
Conversion routines
Each of the three types above need routines to support their “native” usage and probably converting from / to numeric or text representations of the value. Given the three types have the same size then it may also be useful to convert from one format to another. The actualcontentwould not change, just it’s representation. Included with this would be a BINARY(16) so that people who might have had to use other MySQL times to represent these values have an easy way to convert more explicitly to them and if for any reason a conversion back is needed this is also possible.
ALTER TABLE should be aware of these equivalents too so if I have a table defined with a BINARY(16) I can convert it to an IPv6 address/type as a no-op operation (definition only change), in a similar way as can be done with some other conversions (ENUM being a common type that changes but if you add a new value there’s no need to check the table for existing values as the old definition was a subset of the new one).
No incompatible changes in minor versions please
A change such as this can not reasonably be added as a minor version change as if we would break many things. Minor versions should really, really only included bug fixes, or performance improvements, and if a new feature really has to be added by default it must be disabled (for compatibility) and enabled with some sort of special option. Given there’s no agreed way to do this and it is likely to cause all sorts of issues, just do not do it.
That means that a feature such as this can only be added in a new version such as MySQL 5.7 or MariaDB 10.1 both of which are DEV versions, and so allowed to change in any way their authors deem reasonable. I have seen no indication of 5.7 including this functionality and given the time that 5.7 has been about I am inclined to think that an extra change such as this is unlikely to make it there. So MySQL 5.8 then? MariaDB 10.1 development has not been ongoing for that long so maybe such a feature might be considered there.
In the end we do need these new features and long lead times to make them available is a considerable source of frustration for those of us who have a number of systems to upgrade. One thing is a new version going GA, but it’s something else to have all systems upgraded to use that version and thus make it available to developers.
Whatever happens it would be really helpful if the different “MySQL vendors” talk to each other, if they agree that this is a sensible path to take. Having various different interpretations of how these new types should be stored, converted and which associated functions etc are needed would be a user or developer’s nightmare. I understand there is competition, but for something like this it is really important to get it right. The first implementor of such a feature would potentially have an advantage over the others but I would expect usage of this type of data types to be quite popular so agreeing generally on what to do should not be that hard and avoids the different forks from drifting off further apart, something which I think is bad for everyone concerned.
Conclusion
Some people I have spoken share the opinion that having such a set of 128-bit types would be good. It is something else of course to implement that. For those looking for new features to develop in MySQL this is one which in theory is not absolutely necessary but which I think would not only be popular but would be used. In the end MySQL is there to store data, and make it easy to retrieve and it seems clear to me that this type of data is one such usage which while it can be handled differently would really welcome “native” support. I hope that this will happen sometime soon.
Tags:int128,IPv6,mysql,new types,uuid
A2-04-10.MySQL DATA TYPES-Mastering MySQL TIME Data Type
转载自:http://www.mysqltutorial.org/mysql-time/
Mastering MySQL TIME Data Type
Summary: in this tutorial, we will introduce you to the MySQL TIME
data type and show you useful temporal functions to manipulate time data effectively.
Introduction to MySQL TIME data type
MySQL uses the ''HH:MM:SS''
format for querying and displaying a time value that represents a time of day, which is within 24 hours. To represent a time interval between two events, MySQL uses the ''HHH:MM:SS''
format, which is larger than 24 hours.
To define a TIME
column, you use the following syntax:
1
|
column_name
TIME;
|
For example, the following snippet defines a column named start_at
with TIME
data type.
1
|
start_at
TIME;
|
A TIME
value ranges from -838:59:59
to 838:59:59
. In addition, a TIME
value can have fractional seconds part that is up to microseconds precision (6 digits). To define a column whose data type is TIME
with a fractional second precision part, you use the following syntax:
1
|
column_name
TIME(N);
|
N is an integer that represents the fractional part, which is up to 6 digits.
The following snippet defines a column with TIME
data type including 3 digits of fractional seconds.
1
|
begin_at
TIME(3);
|
A TIME
value takes 3 bytes for storage. In case a TIME
value includes fractional second precision, it will take additional bytes based on the number of digits of the fractional second precision. The following table illustrates the storage required for fractional second precision.
Fractional Second Precision | Storage (BYTES) |
0 | 0 |
1, 2 | 1 |
3, 4 | 2 |
5, 6 | 3 |
For example, TIME
and TIME(0)
takes 3 bytes. TIME(1)
and TIME(2)
takes 4 bytes (3 + 1); TIME(3)
and TIME(6)
take 5 and 6 bytes.
MySQL TIME data type example
Let’s take a look at an example of using the TIME
data type for columns in a table.
First, create a new table named tests
that consists of four columns: id
, name
, start_at
, and end_at
. The data types of the start_at
and end_at
columns are TIME
.
1
2
3
4
5
6
|
CREATE TABLE tests (
id INT PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(255) NOT NULL,
start_at TIME,
end_at TIME
);
|
Second, insert a row into the tests
table.
1
2
|
INSERT INTO tests(name,start_at,end_at)
VALUES(''Test 1'', ''08:00:00'',''10:00:00'');
|
Third, query data from the tests
table.
1
2
3
4
|
SELECT
name, start_at, end_at
FROM
tests;
|
Notice that we use ''HH:MM:SS''
as the literal time value in the INSERT
statement. Let’s examine all the valid time literals that MySQL can recognize.
MySQL TIME literals
MySQL recognizes various time formats besides the ''HH:MM:SS''
format that we mentioned earlier.
MySQL allows you to use the ''HHMMSS''
format without delimiter ( : ) to represent time value. For example, ''08:30:00''
and ''10:15:00''
can be rewritten as ''083000''
and ''101500''
.
1
2
|
INSERT INTO tests(name,start_at,end_at)
VALUES(''Test 2'',''083000'',''101500'');
|
However, 108000
is not a valid time value because 80
does not represent the correct minute. In this case, MySQL will raise an error if you try to insert an invalid time value into a table.
1
2
|
INSERT INTO tests(name,start_at,end_at)
VALUES(''Test invalid'',''083000'',''108000'');
|
MySQL issued the following error message after executing the above statement.
1
|
Error
Code: 1292. Incorrect time value: ''108000'' for column ''end_at'' at row 1
|
In addition to the string format, MySQL accepts the HHMMSS
as a number that represents a time value. You can also use SS
, MMSS
. For example, instead of using ''082000''
, you can use 082000
as follows:
1
2
|
INSERT INTO tests(name,start_at,end_at)
VALUES(''Test 3'',082000,102000);
|
For the time interval, you can use the ''D HH:MM:SS''
format where D
represents days with a range from 0 to 34. A more flexible syntax is ''HH:MM''
, ''D HH:MM''
, ''D HH''
, or ''SS''
.
If you use the delimiter:, you can use 1 digit to represent hours, minutes, or seconds. For example, 9:5:0
can be used instead of ''09:05:00''
.
1
2
|
INSERT INTO tests(name,start_at,end_at)
VALUES(''Test 4'',''9:5:0'',100500);
|
Useful MySQL TIME functions
MySQL provides several useful temporal functions for manipulating TIME
data.
Getting to know the current time
To get the current time of the database server, you use the CURRENT_TIME
function. The CURRENT_TIME
function returns the current time value as a string ( ''HH:MM:SS''
) or a numeric value ( HHMMSS
) depending on the context where the function is used.
The following statements illustrate the CURRENT_TIME
function in both string and numeric contexts:
1
2
3
|
SELECT
CURRENT_TIME() AS string_now,
CURRENT_TIME() + 0 AS numeric_now;
|
Adding and Subtracting time from a TIME value
To add a TIME
value to another TIME
value, you use the ADDTIME
function. To subtract a TIME
value from another TIME
value, you use the SUBTIME
function.
The following statement adds and subtracts 2 hours 30 minutes to and from the current time.
1
2
3
4
|
SELECT
CURRENT_TIME(),
ADDTIME(CURRENT_TIME(), 023000),
SUBTIME(CURRENT_TIME(), 023000);
|
In addition, you can use the TIMEDIFF()
function to get a difference between two TIME
values.
1
2
3
4
|
SELECT
TIMEDIFF(end_at, start_at)
FROM
tests;
|
Formatting MySQL TIME values
Although MySQL uses ''HH:MM:SS''
when retrieving and displaying the a TIME
value, you can display the TIME
value in your preferred way using the TIME_FORMAT
function.
The TIME_FORMAT
function is like the DATE_FORMAT
function except that the TIME_FORMAT
function is used to format a TIME
value only.
See the following example.
1
2
3
4
5
6
|
SELECT
name,
TIME_FORMAT(start_at, ''%h:%i %p'') start_at,
TIME_FORMAT(end_at, ''%h:%i %p'') end_at
FROM
tests;
|
In the time format string above:
-
%h
means two-digit hours from 0 to 12. -
%i
means two-digit minutes from 0 to 60. -
%p
means AM or PM.
Extracting hour, minute, and second from a TIME value
To extract the hour, minute, and second from a TIME
value, you use HOUR
, MINUTE
, and SECOND
functions as follows:
Getting UTC time value
To get the UTC time, you use UTC_TIME
function as follows:
1
2
3
|
SELECT
CURRENT_TIME(),
UTC_TIME();
|
In this tutorial, we have been covered a lot about MySQL TIME
data type and some commonly used temporal functions for manipulating TIME
values.
BAT批处理文件,脚本时间值%time:~0,2%%time:~3,2%%time:~6,2%的用法。
最近公司的项目,需要部署一个oracle定时备份脚本,删除掉特定时间前的备份文件。BAT批处理文件结合windows系统(任务计划程序)
正常情况下我们的任务计划会有反馈数值,通过它可以判断这个任务计划上次是否运行正常。
- 代码 0 或 0x0:操作成功完成。
- 代码 1 或 0x1:调用的函数不正确或调用了未知函数。
- 代码 10 或 0xa:环境不正确。
- 代码 0x8009000f:常规访问被拒绝
任务计划程--历史记录里,操作完成,任务完成。但是在任务栏--上次运行结果显示不是操作成功完成(0x0),而是0x1。
通过以上错误代码,去排除调用的函数,发现是脚本文件里的定义时间机制,与设定任务计划时间不匹配造成无法正确运行脚本。
我在任务计划设置的时间是 AM 0:30
bat脚本时间设定如下:
set var=%date:~0,4%%date:~5,2%%date:~8,2%%time:~0,2%%time:~3,2%%time:~6,2%
导致脚本无法正常运行的语句如下:
%time:~0,2%%time:~3,2%%time:~6,2%
如下的各个操作的意义如下:
%time:~0,2% 表示从左向右指针向右偏0位,然后从指针偏移到的位置开始提取2位字符,结果是小时字段数值
%time:~3,2% 表示指针从左向右偏移3位,然后从偏移处开始提取2位字符,结果是分钟字段数值
%time:~6,2% 表示指针从左向右偏移6位,然后从偏移处开始提取2位字符,结果是秒字段数值
//创建时间命名的文件夹
md d:\%date:~0,4%%date:~5,2%%date:~8,2%_%time:~0,2%%time:~3,2%%time:~6,2%
用%time:~0,2%%time:~3,2%%time:~6,2%时有个问题, 就是如果TIME 是00点的时候,电脑显示的是0 不是00所以%time:~0,2%就报错了。
例子:2019-1-20时间1:26:20
set fileDate=%date:~0,4%%date:~5,2%%date:~8,2%%time:~0,2%%time:~3,2%%time:~6,2%
set fileDate2=%date:~0,4%%date:~5,2%%date:~8,2%%time:~1,1%%time:~3,2%%time:~6,2%
echo fileDate:%fileDate%
echo fileDate2:%fileDate2%
fileDate: 20190120 12620(1前面是空格)
fileDate2: 2019012012620
总结:
1)如果要用%time:~0,2%%time:~3,2%%time:~6,2% (运行脚本的时间一定是在10-23点区间,否则0-9(H)脚本调用函数错误,无法运行)
2)如果要用%time:~1,1%%time:~3,2%%time:~6,2% (建议运行脚本的时间在0-9点这个区间,如果是>9点,
比如13点。会造成只显示个位数字3,比如2019-1-20 时间13:26:20 会显示2019012032620 从而影响时间的整体准确性)
3)或者是直接舍去时间,只用日期来定义文件名。
%date:~0,4%%date:~5,2%%date:~8,2%
比如2019-1-20 那么文件名会显示为20190120.(如果需求是每天做一个备份,那么这样命名是没什么影响的,
如果是一天需要N个备份文件,请参照上面两种时间设定)
CNN ValueError:Shapes (10, 4) 和 (10, 128, 128, 4) 不兼容
如何解决CNN ValueError:Shapes (10, 4) 和 (10, 128, 128, 4) 不兼容
我正在为多类音频分类问题构建一个 CNN。我已经从我的音频文件中提取了频谱图特征,我正在尝试将 4D 数组传递给我的 CNN。我还为我的标签执行了 One-Hot 编码。但我不明白为什么我会得到这个 ValueError。请帮助。
这是我的代码:
D = [] # Dataset
for row in df.itertuples():
file_path = os.path.join(''/Users/akellaniranjan/MyWorkspace/Projects/Hobby_Projects/Whistle_Based_Automation/Folder_Approach/'',row.Fold,row.File)
y,sr = librosa.load(file_path,sr = 44100)
ps = librosa.feature.melspectrogram(y=y,sr=sr)
ps = ps[:,:128]
if ps.shape != (128,128): continue
D.append( (ps,row.Class) )
X_train,y_train = zip(*D)
X_train = np.array([x.reshape( (128,128,1) ) for x in X_train])
le = LabelEncoder()
y_train = np_utils.to_categorical(le.fit_transform(y_train))
X_train.shape #Output - (50,1)
y_train.shape #Output - (50,4)
#Model Creation
num_classes = 4 #Number of Classes
model = Sequential()
model.add(Conv2D(256,(5,5),input_shape=(128,1)))
model.add(Activation(''relu''))
model.add(Dropout(0.3))
model.add(Dense(512))
model.add(Activation(''relu''))
model.add(Dropout(0.3))
model.add(Dense(256))
model.add(Activation(''relu''))
model.add(Dropout(0.3))
model.add(Dense(num_classes))
model.add(Activation(''softmax''))
model.compile(loss=''categorical_crossentropy'',metrics=[''accuracy''],optimizer=''adam'')
模型摘要:
Model: "sequential"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
conv2d (Conv2D) (None,124,256) 6656
_________________________________________________________________
activation (Activation) (None,256) 0
_________________________________________________________________
dropout (Dropout) (None,256) 0
_________________________________________________________________
dense (Dense) (None,512) 131584
_________________________________________________________________
activation_1 (Activation) (None,512) 0
_________________________________________________________________
dropout_1 (Dropout) (None,512) 0
_________________________________________________________________
dense_1 (Dense) (None,256) 131328
_________________________________________________________________
activation_2 (Activation) (None,256) 0
_________________________________________________________________
dropout_2 (Dropout) (None,256) 0
_________________________________________________________________
dense_2 (Dense) (None,4) 1028
_________________________________________________________________
activation_3 (Activation) (None,4) 0
=================================================================
Total params: 270,596
Trainable params: 270,596
Non-trainable params: 0
#Fit Model
model.fit(X_train,y_train,batch_size=10,epochs=200)
错误:
Epoch 1/200
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-63-215c349ba276> in <module>
----> 1 model.fit(X_train,epochs=200)
~/miniforge3/envs/DL/lib/python3.8/site-packages/tensorflow/python/keras/engine/training.py in fit(self,x,y,batch_size,epochs,verbose,callbacks,validation_split,validation_data,shuffle,class_weight,sample_weight,initial_epoch,steps_per_epoch,validation_steps,validation_batch_size,validation_freq,max_queue_size,workers,use_multiprocessing)
1098 _r=1):
1099 callbacks.on_train_batch_begin(step)
-> 1100 tmp_logs = self.train_function(iterator)
1101 if data_handler.should_sync:
1102 context.async_wait()
~/miniforge3/envs/DL/lib/python3.8/site-packages/tensorflow/python/eager/def_function.py in __call__(self,*args,**kwds)
826 tracing_count = self.experimental_get_tracing_count()
827 with trace.Trace(self._name) as tm:
--> 828 result = self._call(*args,**kwds)
829 compiler = "xla" if self._experimental_compile else "nonXla"
830 new_tracing_count = self.experimental_get_tracing_count()
~/miniforge3/envs/DL/lib/python3.8/site-packages/tensorflow/python/eager/def_function.py in _call(self,**kwds)
869 # This is the first call of __call__,so we have to initialize.
870 initializers = []
--> 871 self._initialize(args,kwds,add_initializers_to=initializers)
872 finally:
873 # At this point we kNow that the initialization is complete (or less
~/miniforge3/envs/DL/lib/python3.8/site-packages/tensorflow/python/eager/def_function.py in _initialize(self,args,add_initializers_to)
723 self._graph_deleter = FunctionDeleter(self._lifted_initializer_graph)
724 self._concrete_stateful_fn = (
--> 725 self._stateful_fn._get_concrete_function_internal_garbage_collected( # pylint: disable=protected-access
726 *args,**kwds))
727
~/miniforge3/envs/DL/lib/python3.8/site-packages/tensorflow/python/eager/function.py in _get_concrete_function_internal_garbage_collected(self,**kwargs)
2967 args,kwargs = None,None
2968 with self._lock:
-> 2969 graph_function,_ = self._maybe_define_function(args,kwargs)
2970 return graph_function
2971
~/miniforge3/envs/DL/lib/python3.8/site-packages/tensorflow/python/eager/function.py in _maybe_define_function(self,kwargs)
3359
3360 self._function_cache.missed.add(call_context_key)
-> 3361 graph_function = self._create_graph_function(args,kwargs)
3362 self._function_cache.primary[cache_key] = graph_function
3363
~/miniforge3/envs/DL/lib/python3.8/site-packages/tensorflow/python/eager/function.py in _create_graph_function(self,kwargs,override_flat_arg_shapes)
3194 arg_names = base_arg_names + missing_arg_names
3195 graph_function = ConcreteFunction(
-> 3196 func_graph_module.func_graph_from_py_func(
3197 self._name,3198 self._python_function,~/miniforge3/envs/DL/lib/python3.8/site-packages/tensorflow/python/framework/func_graph.py in func_graph_from_py_func(name,python_func,signature,func_graph,autograph,autograph_options,add_control_dependencies,arg_names,op_return_value,collections,capture_by_value,override_flat_arg_shapes)
988 _,original_func = tf_decorator.unwrap(python_func)
989
--> 990 func_outputs = python_func(*func_args,**func_kwargs)
991
992 # invariant: `func_outputs` contains only Tensors,CompositeTensors,~/miniforge3/envs/DL/lib/python3.8/site-packages/tensorflow/python/eager/def_function.py in wrapped_fn(*args,**kwds)
632 xla_context.Exit()
633 else:
--> 634 out = weak_wrapped_fn().__wrapped__(*args,**kwds)
635 return out
636
~/miniforge3/envs/DL/lib/python3.8/site-packages/tensorflow/python/framework/func_graph.py in wrapper(*args,**kwargs)
975 except Exception as e: # pylint:disable=broad-except
976 if hasattr(e,"ag_error_Metadata"):
--> 977 raise e.ag_error_Metadata.to_exception(e)
978 else:
979 raise
ValueError: in user code:
/Users/akellaniranjan/miniforge3/envs/DL/lib/python3.8/site-packages/tensorflow/python/keras/engine/training.py:805 train_function *
return step_function(self,iterator)
/Users/akellaniranjan/miniforge3/envs/DL/lib/python3.8/site-packages/tensorflow/python/keras/engine/training.py:795 step_function **
outputs = model.distribute_strategy.run(run_step,args=(data,))
/Users/akellaniranjan/miniforge3/envs/DL/lib/python3.8/site-packages/tensorflow/python/distribute/distribute_lib.py:1259 run
return self._extended.call_for_each_replica(fn,args=args,kwargs=kwargs)
/Users/akellaniranjan/miniforge3/envs/DL/lib/python3.8/site-packages/tensorflow/python/distribute/distribute_lib.py:2730 call_for_each_replica
return self._call_for_each_replica(fn,kwargs)
/Users/akellaniranjan/miniforge3/envs/DL/lib/python3.8/site-packages/tensorflow/python/distribute/distribute_lib.py:3417 _call_for_each_replica
return fn(*args,**kwargs)
/Users/akellaniranjan/miniforge3/envs/DL/lib/python3.8/site-packages/tensorflow/python/keras/engine/training.py:788 run_step **
outputs = model.train_step(data)
/Users/akellaniranjan/miniforge3/envs/DL/lib/python3.8/site-packages/tensorflow/python/keras/engine/training.py:755 train_step
loss = self.compiled_loss(
/Users/akellaniranjan/miniforge3/envs/DL/lib/python3.8/site-packages/tensorflow/python/keras/engine/compile_utils.py:203 __call__
loss_value = loss_obj(y_t,y_p,sample_weight=sw)
/Users/akellaniranjan/miniforge3/envs/DL/lib/python3.8/site-packages/tensorflow/python/keras/losses.py:157 __call__
losses = call_fn(y_true,y_pred)
/Users/akellaniranjan/miniforge3/envs/DL/lib/python3.8/site-packages/tensorflow/python/keras/losses.py:261 call **
return ag_fn(y_true,y_pred,**self._fn_kwargs)
/Users/akellaniranjan/miniforge3/envs/DL/lib/python3.8/site-packages/tensorflow/python/util/dispatch.py:201 wrapper
return target(*args,**kwargs)
/Users/akellaniranjan/miniforge3/envs/DL/lib/python3.8/site-packages/tensorflow/python/keras/losses.py:1562 categorical_crossentropy
return K.categorical_crossentropy(y_true,from_logits=from_logits)
/Users/akellaniranjan/miniforge3/envs/DL/lib/python3.8/site-packages/tensorflow/python/util/dispatch.py:201 wrapper
return target(*args,**kwargs)
/Users/akellaniranjan/miniforge3/envs/DL/lib/python3.8/site-packages/tensorflow/python/keras/backend.py:4869 categorical_crossentropy
target.shape.assert_is_compatible_with(output.shape)
/Users/akellaniranjan/miniforge3/envs/DL/lib/python3.8/site-packages/tensorflow/python/framework/tensor_shape.py:1134 assert_is_compatible_with
raise ValueError("Shapes %s and %s are incompatible" % (self,other))
ValueError: Shapes (10,4) and (10,4) are incompatible
解决方法
在最后一个块之前添加一个扁平层:
model.add(Dense(256))
model.add(Activation(''relu''))
model.add(Dropout(0.3))
model.add(Flatten()) # <-- this is new
model.add(Dense(num_classes))
model.add(Activation(''softmax''))
更多信息在这里:https://www.tensorflow.org/api_docs/python/tf/keras/layers/Flatten 或在这里:https://keras.io/api/layers/reshaping_layers/flatten/
,我认为对于您的情况,您应该在模型的最后一层之前添加一个 Flatten
层。
>>> model.add(Flatten())
在您的情况下,输出是多维向量,但是您只需要与类对应的一维输出。
更多信息:https://keras.io/api/layers/reshaping_layers/flatten/
PS:您还应该考虑使用 Maxpooling
层,它们将帮助您的模型训练更快,因为它们减少了输入的维度。
CSS选择的使用--获取style=“color: rgba(0, 128, 128, 1)“的标签
在一个需求当中遇到这样一个问题,该如何利用选择器获取如下图所示的span标签呢,它既没有id,也没有class等属性,只有一个属性。
查看CSS选择器使用手册:CSS 选择器参考手册 (w3school.com.cn)
[attribute=value] | [target=_blank] | 选择带有 target="_blank" 属性的所有元素。 |
尝试一下,不带双引号不行,带上双引号就成功了(具体问题具体分析):
我们今天的关于Time to get some 128-bit types into MySQL?_MySQL的分享就到这里,谢谢您的阅读,如果想了解更多关于A2-04-10.MySQL DATA TYPES-Mastering MySQL TIME Data Type、BAT批处理文件,脚本时间值%time:~0,2%%time:~3,2%%time:~6,2%的用法。、CNN ValueError:Shapes (10, 4) 和 (10, 128, 128, 4) 不兼容、CSS选择的使用--获取style=“color: rgba(0, 128, 128, 1)“的标签的相关信息,可以在本站进行搜索。
本文标签: